How to mesh plot sum of sine waves

2 views (last 30 days)
Hello.
I am working on a project for school.
When I run the code, it tells me that 'Z' needs to be a matrix.
I would appreciate any help.
x=-1:0.01:1;
y=-1:0.01:1;
[X,Y]=meshgrid(x,y);
Z=80.*sin(150*x)+90.*sin(200*x);
mesh(X,Y,Z)

Accepted Answer

Star Strider
Star Strider on 28 May 2022
Give it the ‘X’ and ‘Y’ matrix arguments rather than the vector arguments —
x=-1:0.01:1;
y=-1:0.01:1;
[X,Y]=meshgrid(x,y);
Z=80.*sin(150*X)+90.*sin(200*Y);
figure
mesh(X,Y,Z)
With that change, it works.
.
  2 Comments
서영 이
서영 이 on 28 May 2022
Thank you so much for helping me.
I was working with it for a long time..
You are awesome!
Star Strider
Star Strider on 28 May 2022
As always, my pleasure!
Thank you!

Sign in to comment.

More Answers (0)

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!