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

1 view (last 30 days)
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 Comment
Tamim Boubou
Tamim Boubou on 12 Apr 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.

Sign in to comment.

Answers (1)

KSSV
KSSV on 12 Apr 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)

Tags

Community Treasure Hunt

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

Start Hunting!