MATLAB: How to truncate a prolate spheroid

prolate spheroid; truncate; plot

I first generated a prolate spheroid through:
[x y z] = sphere;
x = x;
y = y;
z = 2*z;
surf(x,y,z), axis equal
I need to truncate the prolate spheroid at one end. What is a simple way of doing this?
Cheers,
Nic

Best Answer

Try using logical indexing to set the top flat:
[x y z] = sphere(100);
x = x;
y = y;
z = 2*z;
highZ = z > 1;
x(highZ) = 0;
y(highZ) = 0;
z(highZ) = 1;
surf(x,y,z);
axis equal