-1

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 Answer 1

1

v is a vector. from Matlab's documentation:

The function plots the values in matrix Z as heights above a grid in the x-y plane defined by X and Y

I.e v should be a matrix (in the size of length(x) * length(y)).
Usually, the meshgrid output itself could be passed for the calculations on each of the 2D locations :

[X,Y] = meshgrid(1:0.5:10,1:20);
Z = sin(X) + cos(Y);
surf(X,Y,Z)

see: surf docs

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.