Why can't I generate a 3-d surface when using surf? (file)

2 visualizaciones (últimos 30 días)
WEN SHIN LU
WEN SHIN LU el 22 de En. de 2022
Comentada: WEN SHIN LU el 23 de En. de 2022
My version is 2015b. I use Mac.
x=linspace(-2,2,20);
y=x';
z=y*x;
surf(x,y,z)
And the output has nothing, shownd in picture.

Respuestas (1)

Cris LaPierre
Cris LaPierre el 22 de En. de 2022
Z must be a matrix. In your code, it is only a vector. Follow the eamples on the surf documentation page. You will find meshgrid helpful for this purpose.
x=linspace(-2,2,20);
y=x';
[X,Y] = meshgrid(x,y);
Z = X.*Y;
surf(x,y,Z)
  3 comentarios
Cris LaPierre
Cris LaPierre el 22 de En. de 2022
Good point. I wonder what the issue is then.
WEN SHIN LU
WEN SHIN LU el 23 de En. de 2022
Thank you! I found it's about my files. I created a file called surf before. That's the issue.

Iniciar sesión para comentar.

Categorías

Más información sobre Surface and Mesh Plots en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by