Error using mesh z must be a matrix

3 views (last 30 days)
Anish Sundar Gowthaman
Anish Sundar Gowthaman on 14 Apr 2021
Commented: Daniel Pollard on 15 Apr 2021
>> t=linspace(0,2,100);
>> x=t; y=t. ^2; z=t.^3;
>> plot3 (x,y,z), grid
>> t=linspace(–5,5,50); y=x;
>> z=–7./(1+x.^2+y.^2);
>> mesh(z)
  3 Comments
Daniel Pollard
Daniel Pollard on 15 Apr 2021
I don't know how to answer that when I don't know what the aim of your code is. Star Strider has left an answer - perhaps they figured out what you're after?

Sign in to comment.

Answers (1)

Star Strider
Star Strider on 14 Apr 2021
The arguments to ‘z’ need to be matrices in order for ‘z’ to be a matrix. Use ndgrid or meshgrid (linked to on that page) to create the matrices.
Try this:
t=linspace(0,2,100);
x=t;
y=t.^2;
z=t.^3;
figure
plot3(x,y,z)
grid on
t=linspace(-5,5,50);
y=x;
[X,Y] = ndgrid(x,y);
z= @(x,y) -7./(1+x.^2+y.^2);
figure
mesh(X,Y,z(X,Y))
.

Categories

Find more on Graphics Performance in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!