To this code I want to add the property that every new turn renderes a new color in the plot

1 回表示 (過去 30 日間)
Robert Bag
Robert Bag 2021 年 4 月 18 日
回答済み: Marco Riani 2021 年 4 月 18 日
To this code I want to add the property that every new turn renderes a new color in the plot.
nturns = 8;
t=linspace(0, nturns*2*pi, 10000);
x=t.*cos(t);
y=t.*sin(t);
z=t;
colors = hsv(length(t));
plot3(x,y,t)
xlabel('x')
ylabel('y')
zlabel('t')
view(3)
h = get(gca,'zlabel');%handle
f = get(gca,'xlabel');
g = get(gca,'ylabel');
set(h,'Rotation',0,'VerticalAlignment','middle');
set(f,'Rotation',0,'HorizontalAlignment','center')
set(g,'Rotation',0,'HorizontalAlignment','right')
grid on

回答 (1 件)

Marco Riani
Marco Riani 2021 年 4 月 18 日
Hi Robert,
The above is a preview (I hope this is what you asked)
Here is the code (done for example for the case nturns=5)
close all
nturns = 5;
Colors={'r' 'g' 'b' 'c' 'k'};
hold('on')
for ii=1:nturns
t=linspace((ii-1)*2*pi, ii*2*pi, 10000);
x=t.*cos(t);
y=t.*sin(t);
z=t;
plot3(x,y,t,'Color',Colors{ii})
end
xlabel('x')
ylabel('y')
zlabel('t')
view(3)
h = get(gca,'zlabel');%handle
f = get(gca,'xlabel');
g = get(gca,'ylabel');
set(h,'Rotation',0,'VerticalAlignment','middle');
set(f,'Rotation',0,'HorizontalAlignment','center')
set(g,'Rotation',0,'HorizontalAlignment','right')
grid on

カテゴリ

Help Center および File ExchangeAnnotations についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by