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

조회 수: 3 (최근 30일)
WEN SHIN LU
WEN SHIN LU 2022년 1월 22일
댓글: WEN SHIN LU 2022년 1월 23일
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.

답변 (1개)

Cris LaPierre
Cris LaPierre 2022년 1월 22일
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
Cris LaPierre
Cris LaPierre 2022년 1월 22일
Good point. I wonder what the issue is then.
WEN SHIN LU
WEN SHIN LU 2022년 1월 23일
Thank you! I found it's about my files. I created a file called surf before. That's the issue.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by