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

1 Ansicht (letzte 30 Tage)
AYMERIC BARBIN
AYMERIC BARBIN am 24 Feb. 2021
Kommentiert: AYMERIC BARBIN am 20 Mär. 2021
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

Antworten (1)

Just Manuel
Just Manuel am 24 Feb. 2021
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 Kommentare
Just Manuel
Just Manuel am 2 Mär. 2021
Bearbeitet: Just Manuel am 2 Mär. 2021
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
AYMERIC BARBIN
AYMERIC BARBIN am 20 Mär. 2021
Thanks !

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Graphics Performance finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by