MATLAB: Is it possible to plot a filled surface on matlab

3d plotfilled surfacesMATLABsolid

Hi, i need to plot the following surface as a "closed figure" (in order to calculate its mass later on). Is it possible to do so in matlab? Thank u!!

Best Answer

Try this:
[X,Y] = ndgrid(-2:0.1:2, -1:0.05:1);
Z = 4 - X.^2;
figure
surf(X, Y, Z)
hold on
surf(X(Y==+1)*[1 1], Y(Y==+1)*[1 1], [Z(Y==+1) zeros(size(Z(Y==+1)))]) % One End
surf(X(Y==-1)*[1 1], Y(Y==-1)*[1 1], [Z(Y==-1) zeros(size(Z(Y==-1)))]) % Other End
mesh(X, Y, zeros(size(X))) % Floor
% patch([X(Y==-1); flipud(X(Y==-1))], [Y(Y==-1); flipud(Y(Y==-1))],[Z(Y==-1); zeros(size(Z(Y==-1)))], 'r')
hold off
grid on
xlabel('X')
ylabel('Y')
axis('equal')
view(-45,-30)
producing:
Rotate it to see all the sides. (I left the commented patch call in so you can experiment with it if you want to.)
Related Question