필터 지우기
필터 지우기

Plotting scatter plot in a FOR loop with different colors

조회 수: 20 (최근 30일)
Siddhant Chandra
Siddhant Chandra 2018년 8월 3일
답변: dpb 2018년 8월 3일
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