Borrar filtros
Borrar filtros

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

1 visualización (últimos 30 días)
AYMERIC BARBIN
AYMERIC BARBIN el 24 de Feb. de 2021
Comentada: AYMERIC BARBIN el 20 de Mzo. de 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

Respuestas (1)

Just Manuel
Just Manuel el 24 de Feb. de 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 comentarios
Just Manuel
Just Manuel el 2 de Mzo. de 2021
Editada: Just Manuel el 2 de Mzo. de 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 el 20 de Mzo. de 2021
Thanks !

Iniciar sesión para comentar.

Categorías

Más información sobre Graphics Performance en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by