Z must be a matrix, not a scalar or vector.
Show older comments
t=0:30
x=(1+0.25.*cos(45.*t)).*cos(t)
y=(1+0.25.*cos(45.*t)).*sin(t)
[X,Y] = meshgrid(x,y)
Z=t+2.*sin(45.*t)
surf(X,Y,Z)
not sure why it keep told me the "Z must be a matrix, not a scalar or vector."
Thanks for the help!!
1 Comment
Maybe you intend to make a line in 3D rather than a surface?
t = 0:30;
x = (1+0.25.*cos(45.*t)).*cos(t);
y = (1+0.25.*cos(45.*t)).*sin(t);
z = t+2.*sin(45.*t);
plot3(x,y,z)
Answers (2)
You have have a grid created by meshgrid, so you need a matrix to fill this grid. Not a vector...
It is what it is! :)
t=0:30;
x=(1+0.25.*cos(45.*t)).*cos(t);
y=(1+0.25.*cos(45.*t)).*sin(t);
[X,Y] = meshgrid(x,y);
Z = randn(size(X));
surf(X,Y,Z)
t=0:30 % a vector
x=(1+0.25.*cosd(45.*t)).*cosd(t);
y=(1+0.25.*cosd(45.*t)).*sind(t);
[X,Y] = meshgrid(x,y) % X and Y matrices
Z=X+2.*sin(45.*Y); % do you mean this ?
surf(X,Y,Z);
shading interp
Categories
Find more on Line Plots in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

