简体   繁体   中英

Function plotting using mesh and meshgrid in matlab

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.

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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM