Vectors of different length when using plot3.

조회 수: 2 (최근 30일)
Snirisa  Gödel
Snirisa Gödel 2013년 9월 25일
댓글: Snirisa Gödel 2013년 9월 26일
Basically I want to do a 3D plot of 100 circles with different radii and on a new height plane(h) for each circle. The radius increase for each circle(constant increase) and h increase constantly.
I've never used plot3 before so this code is from the top of my head. I was thinking of using a for loop for both r and h as suggested below. But where should I begin the loop for h? In the beginning(just under r) or as below? And what does it mean that "vectors must be of same length". Which vector?
if true
% for r=1:1:100
t=linspace(0,2*pi);
x=r*cos(t);
y=r*sin(t);
for h=100:100:10000
z=h;
plot3(x,y,z)
end
end

채택된 답변

Image Analyst
Image Analyst 2013년 9월 26일
You might want to rethink your parameters because it sort of looks like a mess with way too many circles on the screen, but anyway, run this:
for r=1:1:100
t=linspace(0,2*pi);
x=r*cos(t);
y=r*sin(t);
for h=100:100:10000
z=h * ones(1, length(t));
plot3(x,y,z);
if r == 1 && h == 100
hold on;
% Enlarge figure to full screen.
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
end
drawnow;
end
end
  댓글 수: 1
Snirisa  Gödel
Snirisa Gödel 2013년 9월 26일
Thank you, this looks much closer to what I had in mind. As you mentioned, this looks like a mess but I'm sure it's just a matter of changing parameters in this case. I appreciate it.

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

추가 답변 (2개)

dpb
dpb 2013년 9월 25일
Why not try it and see if it's the effect desired?
From
doc plot3
...
plot3(x,y,z), where x, y and z are three vectors of the same length, ...

Roger Stafford
Roger Stafford 2013년 9월 26일
Change the line
plot3(x,y,z)
to
plot3(x,y,repmat(z,1,size(t,2)))
hold on

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by