Matlab error, Z must be a matrix, not a scalar or vecto

1 visualización (últimos 30 días)
Muhammad Fahad Arshad
Muhammad Fahad Arshad el 12 de Abr. de 2021
Comentada: Tamim Boubou el 12 de Abr. de 2021
I am unable to generate mesh or surf while using this code
" z must be a matrix, not a scalar or vector"
r= 5;
theta= 60 ;
ro=5;
w1=200;
w2=300;
t=0:1:60;
dt=diff(t);
x=ro*cos(w1.*t)+r.*cos(theta+(w1+w2).*t)
dx=diff(x);
y=ro*sin(w1.*t)+r.*sin(theta+(w1+w2).*t)
dy=diff(y);
a=(dx./dt).^2;
b=(dy./dt).^2;
v=sqrt(a+b);
[x,y]=meshgrid(x,y);
surf(x,y,v)
  1 comentario
Tamim Boubou
Tamim Boubou el 12 de Abr. de 2021
The function "surf" takes three parameters that are all matricies. From your code, the first two arguments (x,y) are both matricies, hence no issue, but the third argument v is defined as a vector, which is the reason for the error.
Hope this helps.

Iniciar sesión para comentar.

Respuestas (1)

KSSV
KSSV el 12 de Abr. de 2021
r= 5;
theta= 60 ;
ro=5;
w1=200;
w2=300;
t=0:1:60;
dt=diff(t);
dt = unique(dt) ;
x=ro*cos(w1.*t)+r.*cos(theta+(w1+w2).*t) ;
y=ro*sin(w1.*t)+r.*sin(theta+(w1+w2).*t) ;
[x,y]=meshgrid(x,y);
dx=gradient(x);
dy=gradient(y);
a=(dx./dt).^2;
b=(dy./dt).^2;
v=sqrt(a+b);
surf(x,y,v)

Categorías

Más información sobre Matrix Indexing 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