MATLAB: How to plot a cone via fsurf

anonymusconefunctionMATLABplot

Hello! I am experiencing some problems when trying to plot a cone in ML using the fsurf function.
When using meshgrid and surf everything works as expected (the height of the cone is supposed to be three times the radius, that's where the formula for z comes from):
radius = 2;
r = linspace(0,radius);
phi = linspace(0,2*pi);
[R, PHI] = meshgrid(r,phi);
X = R .* cos(PHI)
Y = R .* sin(PHI)
Z = -3*R + 3 * radius;
surf(X,Y,Z);
I have this example for a cylinder in ML:
R = 2;
xZ = @(t,z) R*cos(t);
yZ = @(t,z) R*sin(t);
zZ = @(t,z) z;
fsurf(xZ, yZ, zZ);
This example works fine but I guess I have not really understood how everything comes together or how these anonymus functions work. I think this example can be modified to plot a cone by altering zZ but I do not really know how. Maybe someone can give me a push in the right direction.

Best Answer

I have found a solution and in case anyone should come across the same problem:
xCone = @(s,t) (coneRadius - 1/3 * t) .* cos(s);
yCone = @(s,t) (coneRadius - 1/3 * t) .* sin(s);
zCome = @(s,t) t;
fsurf(xCone, yCone, zCone, [0, 2*pi, 0, 3*coneRadius]);
This will plot a 3D cone with a given radius (coneRadius) using fsurf. It is important to know that this cone has a fixed height of three times its radius.