Z must be a matrix, not a scalar or vector.

1 次查看(过去 30 天)
Hello,
I would like to turn the figure drawn by this code:
t = linspace(-10,10,1000);
xt = exp(-t./10).*sin(5*t);
yt = exp(-t./10).*cos(5*t);
p = plot3(xt,yt,t);
Which gives this
To a figure with a filled surface, like one can do with surf, like so:
[X,Y] = meshgrid(1:0.5:10,1:20);
Z = sin(X) + cos(Y);
surf(X,Y,Z)
But,
surf(xt,yt,t);
gives this error: "Z must be a matrix, not a scalar or vector."
Thanks for your support

回答(1 个)

Just Manuel
Just Manuel 2021-2-24
Well, have a look, what X, Y and Z are that allow you to make a surface.
Meshgrid gives you matrices for X and Y, thus Z is also a matrix (20 by 19 in your example).
You need to specify height values in t, so express it as a function of X and Y.
Cheers
Manuel
  2 个评论
Just Manuel
Just Manuel 2021-3-2
编辑:Just Manuel 2021-3-2
Try something along the lines of
[X,Y] = meshgrid(-2:0.2:2,-2:0.2:2);
[phi,r] = cart2pol(X,Y);
Z = -10.*log(r);
surf(X,Y,Z)
Which yields this:
Or even better: use the approach from this answer:
r = 0.5:0.1:2;
phi = 0:0.1:2*pi;
[R,PHI] = meshgrid(r,phi);
Z = -10.*log(R);
surf(R.*cos(PHI), R.*sin(PHI), Z)
Which yields this:
And please accept the answer, if it was of use to you.
Cheers
Manuel

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Graphics Performance 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by