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

1 vue (au cours des 30 derniers jours)
AYMERIC BARBIN
AYMERIC BARBIN le 24 Fév 2021
Commenté : AYMERIC BARBIN le 20 Mar 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

Réponses (1)

Just Manuel
Just Manuel le 24 Fév 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 commentaires
Just Manuel
Just Manuel le 2 Mar 2021
Modifié(e) : Just Manuel le 2 Mar 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 le 20 Mar 2021
Thanks !

Connectez-vous pour commenter.

Catégories

En savoir plus sur Graphics Performance dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by