Z must be a matrix, not scalar or vector
6 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Daniel Walker
el 4 de Ag. de 2020
Comentada: Daniel Walker
el 4 de Ag. de 2020
I've seen a bunch of other people ask similar questions, my code is a bit different.
The following were my originial commands before I tried to code it:
>> t=linspace(0, 2*pi);
>> x=2*cos(t);
>> y=sin(t)+cos(t)-1;
>> z=sin(t);
>> surf(x,y,z)
Error using surf (line 71)
Z must be a matrix, not a scalar or vector.
I am trying to graph the equation of the curve of intersection of curve (x^2)/2 + 2z^2=2 and plane x-y+z-1=0
Thanks for any help I can get!
0 comentarios
Respuesta aceptada
Cris LaPierre
el 4 de Ag. de 2020
z needs to be the same size as X and Y. Perhaps you mean to do something like this?
t=linspace(0, 2*pi);
T = meshgrid(t);
x=2*cos(T);
y=sin(T)+cos(T)-1;
z=sin(T)
surf(x,y,z)
Más respuestas (1)
Walter Roberson
el 4 de Ag. de 2020
t=linspace(0, 2*pi);
That is a row vector.
x=2*cos(t);
Row Vector.
y=sin(t)+cos(t)-1;
Row vector.
z=sin(t);
Row vector that does not depend upon x or y.
surf(x,y,z)
x, y, z are all row vectors.
In some cases it is valid for x and y to be vectors for surf, provided that length(x) = size(z,2) and length(y) = size(z,1). However, with your z being a row vector, then size(z,1) = 1 so your y would have to be length 1 to match... and even that would not be permitted as it does not give enough input values to form a surface out of.
In the code you show the image of, you do
[X,Y] = meshgrid(x,y);
and after that X and Y would be 2D matrices. However, that code still creates z from the row vector t.
curve of intersection of curve (x^2)/2 + 2z^2=2 and plane x-y+z-1=0
It is not at all obvious that you are plotting the intersection in what you posted. It looks to me more as if you are trying to plot the first curve in parameteric form. You could use more comments.
Ver también
Categorías
Más información sobre Surface and Mesh Plots en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!