plot multiple lines with same sample size and apply colour string
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Yuktha Andie Ravinthiran
el 17 de Feb. de 2022
Comentada: William Rose
el 19 de Feb. de 2022
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 comentarios
Respuesta aceptada
William Rose
el 17 de Feb. de 2022
Editada: William Rose
el 17 de Feb. de 2022
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 comentario
William Rose
el 19 de Feb. de 2022
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.
Más respuestas (0)
Ver también
Categorías
Más información sobre Bar Plots en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!