Clear Filters
Clear Filters

Plotting scatter plot in a FOR loop with different colors

20 views (last 30 days)
I am plotting a scatter plot from 'n'(=7,for now) Excel files. I am running a FOR loop to read through each Excel file and plot the scatter plot. But I am not able to change the color of the scatter plot each time the loop begins afresh. I basically want those 'n' scatter plots where each scatter plot is corresponding to a different Excel file (either filled circles or '*') in different colors, on the same graph. Can somebody please help me with this? Code is below:
for k=1:7
FileName2 = [' _xyz_',num2str(k),'.xls'];
filename3 =fullfile('ABC', FileName2);
[v,T,vT]=xlsread(filename3);
t=v(:,1);y=v(:,5);
sz = 25;
scatter(t,y,sz,'filled')
axis([115000 148000 35 160])
end

Accepted Answer

dpb
dpb on 3 Aug 2018
clrs=['r','g','b','c','m','y','k'];
for i=1:N
...
scatter(y,z,sz,c(i),'filled')
...
end
for the defined color mnemonics for red,green,blue,cyan,magenta,yellow,black. Rearrange order as wished; if want more or custom colors, use RGB triplets. Doc for 'linespec' shows examples.
You can do similar for symbols as well to iterate over them, of course.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!