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

1 次查看(过去 30 天)
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 个评论
Tamim Boubou
Tamim Boubou 2021-4-12
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.

请先登录,再进行评论。

回答(1 个)

KSSV
KSSV 2021-4-12
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)

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by