Reputation: 75
I have to represent this function: c = y * sin(x) using mesh. Where:
x = -10:10
y = 0:3:30
My code looks like this:
[X,Y] = meshgrid(x,y);
C = Y*sin(X)';
mesh(X,Y,C);
But when I run it I get the following error:
"Error using mesh (line 71) Data dimensions must agree.".
How do I fix this? I'm not sure how to plot a function where the variables are multiplied.
Upvotes: 0
Views: 203
Reputation: 26
I don't have a MATLAB licence to test it. But I guess the problem is that you are using the *
operator, which does a matrix matrix multiplication. You need to do an element-wise multiplication using .*
, and remove the transpose.
C = Y.*sin(X);
Upvotes: 1