MATLAB: How to change a single line color and style in a graph

graphmatrix array

Hi! I have created a code that will generate 3 figures, with 8 lines in each figure.
I want to change the color and style of the lines individually, but can't seem to find a way that works. Any advice would be really helpful!
The code is shown here.
phistep = 0.0001;
phiarr = (0.25:phistep:5)';
numberofvalues = (5-0.25)/phistep+1;
d11 = 65493;
d12 = 1267;
d22 = 32243;
d66 = 1867;
marr = [1,2,3,4];
narr = [1,2];
for c = [0,1,2]
linevalues = zeros(numberofvalues,length(marr)*length(narr));
for m = marr
for n = narr
for i = 1:numberofvalues
phi = phiarr(i);
idx = (m-1)*(length(narr))+n;
linevalues(i,idx) = ((pi^2)/(100^2))*(d11*(m/phi)^4 + 2*(d12+2*d66)*(m*n/phi)^2 + d22*n^4)/((m/phi)^2+c*n^2);
end
end
end
figure(c+1)
phimat = repmat(phiarr,1,length(marr)*length(narr));
[y_min, idx]=min(linevalues);
x_min = phimat(idx);
plot(phimat,linevalues,x_min,y_min,'rx');
ylim([0 600]);
xlabel('aspect ratio');
ylabel('buckling load');
grid on
legend('m=1,n=1','m=1,n=2','m=2,n=1','m=2,n=2','m=3,n=1','m=3,n=2','m=4,n=1','m=4,n=2')
end

Best Answer

Try this. It uses the color specified in colors variable
phistep = 0.0001;
phiarr = (0.25:phistep:5)';
numberofvalues = (5-0.25)/phistep+1;
d11 = 65493;
d12 = 1267;
d22 = 32243;
d66 = 1867;
marr = [1,2,3,4];
narr = [1,2];
colors = [0 0 0; %% <---- Define colors
0 0 1;
0 1 0;
0 1 1;
1 0 0;
1 0 1;
1 1 0;
1 1 1]; % Give RGB value for eight lines. Each value can vary from 0 to 1
for c = [0,1,2]
linevalues = zeros(numberofvalues,length(marr)*length(narr));
for m = marr
for n = narr
for i = 1:numberofvalues
phi = phiarr(i);
idx = (m-1)*(length(narr))+n;
linevalues(i,idx) = ((pi^2)/(100^2))*(d11*(m/phi)^4 + 2*(d12+2*d66)*(m*n/phi)^2 + d22*n^4)/((m/phi)^2+c*n^2);
end
end
end
figure(c+1)
ax = axes();
hold(ax); % we need to hold the axes
phimat = repmat(phiarr,1,length(marr)*length(narr));
[y_min, idx]=min(linevalues);
x_min = phimat(idx);
% Loop is needed to specify different colors
for i=1:8
plot(phimat(:,i),linevalues(:,i),'Color', colors(i,:));
end
plot(x_min,y_min,'rx');
ylim([0 600]);
xlabel('aspect ratio');
ylabel('buckling load');
grid on
legend('m=1,n=1','m=1,n=2','m=2,n=1','m=2,n=2','m=3,n=1','m=3,n=2','m=4,n=1','m=4,n=2')
end
Related Question