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)
Afficher commentaires plus anciens
beginnermatlab
le 20 Juin 2021
Commenté : Sulaymon Eshkabilov
le 21 Juin 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 commentaires
Réponse acceptée
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)
2 commentaires
Plus de réponses (0)
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!