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

1 Ansicht (letzte 30 Tage)
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

Antworten (1)

Marco Riani
Marco Riani am 18 Apr. 2021
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

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by