working of surf function

조회 수: 12 (최근 30일)
RajyaLakshmi
RajyaLakshmi 2015년 6월 24일
편집: Stephen23 2015년 6월 24일
Plot the following surfaces using the surf function:
a) Sine surface
x = sin(u)
y = sin(v)
z = sin(u +v )
where 0 <= u <= 2*pi, and 0 <=v <= 2*pi.
I executed the following code :
u=[0:pi/4:2*pi];
v=[0:pi/4:2*pi];
x=sin(u);
y=sin(v);
z=sin(u+v);
surf(x,y,z);colorbar;xlabel('sin(u)');ylabel('sin(v)');zlabel('sin(u+v)');title('Sine Surface');
After executing the above code I got the following error
Error using surf (line 75) Z must be a matrix, not a scalar or vector
Here Z is a matrix of size [1 9]. can anyone tell me the reason:
  댓글 수: 1
Jan
Jan 2015년 6월 24일
I've edited the question to format the code. Please use the "{} Code" button for posting code. Thanks.

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

답변 (2개)

Stephen23
Stephen23 2015년 6월 24일
편집: Stephen23 2015년 6월 24일
surf needs matrices to plot this data, so you need to convert the two vectors u and v into matrices... this is exactly what meshgrid is for:
u = 0:pi/4:2*pi;
v = 0:pi/4:2*pi;
[uM,vM] = meshgrid(u,v);
I am sure that you can manage the rest, you just need to use the uM and vM values instead of u and v. You might also like to decrease the step size: around one twentieth looks nice.

Jan
Jan 2015년 6월 24일
Please read the documentation of the surf command. There you find working examples, which explain, that Z must be a matrix of the size length(X)*length(Y):
If X and Y are vectors, length(X) = n and length(Y) = m, where [m,n] = size(Z)

카테고리

Help CenterFile Exchange에서 Lighting, Transparency, and Shading에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by