Surf Plot error code with Z having to be defined as a matrix, not scalar or vector

1 vue (au cours des 30 derniers jours)
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!

Réponse acceptée

Sulaymon Eshkabilov
Sulaymon Eshkabilov le 20 Juin 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)

Plus de réponses (0)

Catégories

En savoir plus sur MATLAB dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by