plot multiple lines with same sample size and apply colour string

2 ビュー (過去 30 日間)
Yuktha Andie Ravinthiran
Yuktha Andie Ravinthiran 2022 年 2 月 17 日
コメント済み: William Rose 2022 年 2 月 19 日
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 Center および File ExchangeBar Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by