Alternating color code in a dotted Circle

1 view (last 30 days)
I have plotted a circle with red dots using the sine and cosine functions , but I am trying to edit it such that every other dot color is blue. Here is my code
t=0:0.1:2*pi;
figure
hold on
for i=1:numel(t)
sine=sin(t);
cosine=cos(t);
end
plot(sine,cosine,'r.')
xlim([-1.25 1.25])
ylim([-1 1])
axis equal

Accepted Answer

Cris LaPierre
Cris LaPierre on 19 Mar 2021
All markers in a series will have the same color, so the best approach I can think of is to plot two separate series, one with red markers and the other with blue.
t=0:0.1:2*pi;
figure
sine=sin(t);
cosine=cos(t);
plot(sine(1:2:end),cosine(1:2:end),'r.')
hold on
plot(sine(2:2:end),cosine(2:2:end),'b.')
hold off
xlim([-1.25 1.25])
ylim([-1 1])
axis equal

More Answers (0)

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!