Plotting scatter plot in a FOR loop with different colors

20 次查看(过去 30 天)
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

采纳的回答

dpb
dpb 2018-8-3
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.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Scatter Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by