필터 지우기
필터 지우기

How do I change height and colour of cylinder made with SURF?

조회 수: 8 (최근 30일)
Cheng Yoong
Cheng Yoong 2011년 5월 27일
답변: Tomasz 2021년 11월 7일
By default,we can use Matlab to plot a cylinder using surf command. This is what I've tried so far:
[x,y,z]=cylinder(10);
surf(x,y,z)
the result came out is a blue cylinder with radius 10. how do i change the colour and height in this case?

채택된 답변

Jan
Jan 2011년 5월 27일
[x,y,z] = cylinder(10);
z(2, :) = 10;
surf(x,y,z, 'FaceColor', [1,0,0]);
  댓글 수: 4
Cheng Yoong
Cheng Yoong 2011년 5월 27일
Is it possible to plot the cylinder horizontally?
If possible can you show me how?
Jan
Jan 2011년 5월 27일
@Cheng: You can try it by your self. "z(2, :)=10; disp(z); z(2, :)=3; disp(z)".
What about "surf(x,z,y)" or "surf(z,y,x)"?

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

추가 답변 (4개)

Walter Roberson
Walter Roberson 2011년 5월 27일
The simplest way to plot horizontally might be to change the viewpoint and relabel the axes :)
Otherwise you might need to create an hgtransform() that does a rotation and parent the surface to it using surf(x,y,z,'Parent',TheHGHandle)

Patrick Kalita
Patrick Kalita 2011년 7월 13일
Here's how you would do it with an hgtransform and makehgtform:
% Make the hgtransform and the surface; parent the surface to the hgtransform
[x,y,z] = cylinder(10);
h = hgtransform;
surf(x,y,z, 'Parent', h, 'FaceColor', 'r');
view(3)
% Make it taller
set(h, 'Matrix', makehgtform('scale', [1 1 10]))
% Tip it over and make it taller
set(h, 'Matrix', makehgtform('xrotate', pi/2, 'scale', [1 1 10]))

Álvaro Romero Calvo
Álvaro Romero Calvo 2018년 10월 7일
편집: Walter Roberson 2018년 10월 11일

Tomasz
Tomasz 2021년 11월 7일
k=0:0.2:1;
[X,Y,Z]=cylinder(k,3);
figure
surf(X(1:2,:),Y(1:2,:),Z(1:2,:),'facecolor',[0,0,1])
hold on
surf(X(2:3,:),Y(2:3,:),Z(2:3,:),'facecolor',[0 ,0.4470, 0.7410])
surf(X(3:4,:),Y(3:4,:),Z(3:4,:),'facecolor',[0,1,1])
surf(X(4:5,:),Y(4:5,:),Z(4:5,:),'facecolor',[1,1,0])
surf(X(5:6,:),Y(5:6,:),Z(5:6,:),'facecolor',[1,0,0])
hold off

카테고리

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