MATLAB: How to plot three different colored groups of log plots (5 lines, 5 lines, 2 lines) on the same axes

particle size distribution comparison log plot line plot

Hi there,
I have 12 datasets and I want to be able to plot them in three different colour groups (1 to 5, 6 to 10 and 11 to 12) against the same x axis. Here is what I have (below). As you can see, all lines are different colours which doesn't match my legend.
Thanks in advance.
psd = STBcum_hstconc_dia;
x = psd(:,1);
y1 = psd(:,3);
y2 = psd(:,5);
y3 = psd(:,6);
y4 = psd(:,7);
y5 = psd(:,8);
y6 = psd(:,9);
y7 = psd(:,10);
y8 = psd(:,11);
y9 = psd(:,12);
y10 = psd(:,13);
y11 = psd(:,14);
y12 = psd(:,15);
figure(1)
hold on
plot(log10(x), y1,log10(x), y2,log10(x), y3,log10(x), y4,log10(x), y5,log10(x), y6,log10(x), y7,log10(x), y8,log10(x), y9,log10(x), y10,log10(x), y11,log10(x), y12, 'linewidth', 1) % Bar of ‘hst_irl’ on log10 of ‘dia_irl’
hold off
grid
logxts = [0:2 log10(300.1)];
set(gca,'XTick', logxts)
expxts = 10.^(logxts);
set(gca, 'XTickLabel', floor(1*expxts)/1)
axis([min(logxts) max(logxts) 0 350])
ylim auto
legend ('show','0-3m','4-7.5m','8.5-10m')

Best Answer

h = plot(log10(x), psd(:, [1 3 5 6 7 8 9 10 11 12 13 14 15]), 'linewidth', 1);
set(h(1:5), 'Color', [1 0 0]);
set(h(6:10), 'Color', [0 1 0]);
set(h(11:12), 'Color', [0 0 1]);
legend(h([1 6 11]), '0-3m', '4-7.5m', '8.5-10m');
Related Question