plot multiple lines with same sample size and apply colour string

조회 수: 2 (최근 30일)
p2 = 'filename.xlsx'
hold on
set(groot,'defaultLineLineWidth',1.5)
ex = xlsread(p2,'1','E2:E37');
ey = xlsread(p2,'1','C2:C361');
eplot = plot(ex,rescale(ey(1:36)),'r-.',ex,rescale(ey(37:72)),'color','#D95319',ex,ey(73:108),'color','#EDB120');
legend('1','2','3')
I can plot 2 lines but when I add the third, it says there is error using plot and error using matlab_graphs
When plotting, is there a way to specify plot ey in chunks of 36 and apply a rainbow colourstring to the lines plotted

채택된 답변

William Rose
William Rose 2022년 2월 17일
편집: William Rose 2022년 2월 17일
Yes it is possible. Use the "hold on" command and write a for loop. Inside the ploop, plot successive sets for 36 points.
See below.
N=432;
x=rand(1,N); %create N data points
M=36;
P=floor(N/M); %number of loop passes to make
colors=[1,0,0; 1,.5,0; 1,1,0; .5,1,0; ...
0,1,0; 0,1,.5; 0,1,1; 0,.5,1;...
0,0,1; .5,0,1; 1,0,1; 1,0,.5]; %colors to use
figure;
hold on
for i=1:P
plot((i-1)*M+1:i*M,x((i-1)*M+1:i*M),'Color',colors(i,:));
end
Try it.
  댓글 수: 1
William Rose
William Rose 2022년 2월 19일
I see now that you plotted your 36 point groups all versus the same x-axis values. To do this, change the "plot" line in the code above:
N=432;
x=rand(1,N); %create N data points
M=36;
P=floor(N/M); %number of loop passes to make
colors=[1,0,0; 1,.5,0; 1,1,0; .5,1,0; ...
0,1,0; 0,1,.5; 0,1,1; 0,.5,1;...
0,0,1; .5,0,1; 1,0,1; 1,0,.5]; %colors to use
figure;
hold on
for i=1:P
plot(1:M,x((i-1)*M+1:i*M),'Color',colors(i,:));
legstr{i}=sprintf('Run %d',i);
end
legend(legstr);
I added a legend line.
Good luck.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Legend에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by