Surf Plot error code with Z having to be defined as a matrix, not scalar or vector
1 view (last 30 days)
Show older comments
beginnermatlab
on 20 Jun 2021
Commented: Sulaymon Eshkabilov
on 21 Jun 2021
I'm trying to graph a 3D function z=(x-y)/(1+y) as a challenge.
Here is what I have so far:
>> x=-1:1:1;
>> y=-1:1:1;
>> [X,Y]=meshgrid(x,y);
>> Z=[(x-y)/(1+y)];
>> surf(X,Y,Z)
It is returning:
Error using surf (line 71)
Z must be a matrix, not a scalar or vector.
I do not know what the problem is with my code, can someone help? Thank you!
0 Comments
Accepted Answer
Sulaymon Eshkabilov
on 20 Jun 2021
There are a couple of errs. Here is the corrected code
x=-1:1:1;
y=-1:1:1;
[X,Y]=meshgrid(x,y);
% Ver 1.
Z=(x(:)-y)./(1+y);
surf(X,Y,Z')
% or Ver 2.
Z=(X-Y)./(1+Y);
surf(X,Y,Z)
2 Comments
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!