plot multiple lines with same sample size and apply colour string
1 次查看(过去 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
0 个评论
采纳的回答
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
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 Exchange 中查找有关 Bar Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!