How could I create a 3D binary matrix/image from a surface mesh in Matlab?

For instance, when I create ellipsoid using:

```
[x, y, z] = ellipsoid(0,0,0,5.9,3.25,3.25,30);

```

X, Y and X are all 2D matrix with size 31 x 31.

Edited based on suggestion of @Magla:

```
function Create_Mask_Basedon_Ellapsoid3()
         close all
        SurroundingVol  = [50, 50, 20];
        %DATA
        [MatX,MatY,MatZ] = meshgrid(-24:1:25, -24:1:25, -9:1:10);
        [mask1, x, y, z] = DrawEllipsoid([0, -10, 0], [6, 3, 3], MatX,MatY,MatZ);
        [mask2, x2, y2, z2] = DrawEllipsoid([15, 14, 6], [6, 3, 3], MatX,MatY,MatZ);
        mask =  mask1 + mask2;

        %Surface PLOT
        figure('Color', 'w');
        subplot(1,2,1);

        %help: Ideally I would like to generate surf plot directly from combined mask= mask1 + mask2;
        s = surf(x,y,z); hold on;
        s2 = surf(x2,y2,z2); hold off;     
        title('SURFACE', 'FontSize', 16);
        view(-78,22)

        subplot(1,2,2);
        xslice = median(MatX(:));
        yslice = median(MatY(:));
        zslice = median(MatZ(:));

        %help: Also how do I decide correct "slice" and angles to 3D visualization.
        h = slice(MatX, MatY, MatZ, double(mask), xslice, yslice, zslice)
        title('BINARY MASK - SLICE VOLUME', 'FontSize', 16);
        set(h, 'EdgeColor','none');   
        view(-78, 22)
        %az = 0; el = 90;
        %view(az, el);

    end

    function [mask, Ellipsoid_x, Ellipsoid_y, Ellipsoid_z] = DrawEllipsoid(CenterEllipsoid, SizeEllipsoid, MatX, MatY, MatZ)
        [Ellipsoid_x, Ellipsoid_y, Ellipsoid_z] =  ellipsoid(CenterEllipsoid(1), CenterEllipsoid(2), CenterEllipsoid(3), SizeEllipsoid(1)/2 , SizeEllipsoid(2)/2 , SizeEllipsoid(3)/2 ,30);
        v = [Ellipsoid_x(:), Ellipsoid_y(:), Ellipsoid_z(:)];                       %3D points
        %v = [x(:), y(:), z(:)];                                                    %3D points
        tri = DelaunayTri(v);                                                       %triangulation
        SI = pointLocation(tri,MatX(:),MatY(:),MatZ(:));                            %index of simplex (returns NaN for all points outside the convex hull)
        mask = ~isnan(SI);                                                          %binary
        mask = reshape(mask,size(MatX));                                            %reshape the mask 
    end

```