Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Plotting multiple lines on the same graph, different color

Subject: Plotting multiple lines on the same graph, different color

From: Ulrik Nash

Date: 16 Oct, 2011 04:22:12

Message: 1 of 5

Hi Everyone,

Suppose I have the following code, which plots different lines on a graph:

t = 1:timeperiods;
for i = 1:num_files
    plot(t,A(1:timeperiods,i))
    hold all
    plot(t,B(1:timeperiods,i))
end

For each loop (i.e. for each pair of lines) I wish to change the colour of lines. How can I amend the code to do this?

Regards,

Ulrik.

Subject: Plotting multiple lines on the same graph, different color

From: salman

Date: 16 Oct, 2011 07:17:10

Message: 2 of 5

"Ulrik Nash" <uwn@sam.sdu.dk> wrote in message <j7dm5k$35k$1@newscl01ah.mathworks.com>...
> Hi Everyone,
>
> Suppose I have the following code, which plots different lines on a graph:
>
> t = 1:timeperiods;
> for i = 1:num_files
> plot(t,A(1:timeperiods,i))
> hold all
> plot(t,B(1:timeperiods,i))
> end
>
> For each loop (i.e. for each pair of lines) I wish to change the colour of lines. How can I amend the code to do this?
>
> Regards,
>
> Ulrik.
for m=1:x
hold on
plot(t,y(m),'Color',rand(1,3)))
end

Subject: Plotting multiple lines on the same graph, different color

From: Ulrik Nash

Date: 16 Oct, 2011 16:26:11

Message: 3 of 5

"salman " <salmanabdullah9@gmail.com> wrote in message <j7e0dm$26s$1@newscl01ah.mathworks.com>...
> "Ulrik Nash" <uwn@sam.sdu.dk> wrote in message <j7dm5k$35k$1@newscl01ah.mathworks.com>...
> > Hi Everyone,
> >
> > Suppose I have the following code, which plots different lines on a graph:
> >
> > t = 1:timeperiods;
> > for i = 1:num_files
> > plot(t,A(1:timeperiods,i))
> > hold all
> > plot(t,B(1:timeperiods,i))
> > end
> >
> > For each loop (i.e. for each pair of lines) I wish to change the colour of lines. How can I amend the code to do this?
> >
> > Regards,
> >
> > Ulrik.
> for m=1:x
> hold on
> plot(t,y(m),'Color',rand(1,3)))
> end


I am sorry, but could you please answer within the context of my code?

Subject: Plotting multiple lines on the same graph, different color

From: salman

Date: 17 Oct, 2011 00:07:10

Message: 4 of 5

"Ulrik Nash" <uwn@sam.sdu.dk> wrote in message <j7f0j3$3jc$1@newscl01ah.mathworks.com>...
> "salman " <salmanabdullah9@gmail.com> wrote in message <j7e0dm$26s$1@newscl01ah.mathworks.com>...
> > "Ulrik Nash" <uwn@sam.sdu.dk> wrote in message <j7dm5k$35k$1@newscl01ah.mathworks.com>...
> > > Hi Everyone,
> > >
> > > Suppose I have the following code, which plots different lines on a graph:
> > >
> > > t = 1:timeperiods;
> > > for i = 1:num_files
> > > plot(t,A(1:timeperiods,i))
> > > hold all
> > > plot(t,B(1:timeperiods,i))
> > > end
> > >
> > > For each loop (i.e. for each pair of lines) I wish to change the colour of lines. How can I amend the code to do this?
> > >
> > > Regards,
> > >
> > > Ulrik.
> > for m=1:x
> > hold on
> > plot(t,y(m),'Color',rand(1,3)))
> > end
>
>
> I am sorry, but could you please answer within the context of my code?

 t = 1:timeperiods;
> > > for i = 1:num_files
hold on
> > > subplot(211)
plot(t,A(1:timeperiods,i),'Color',rand(1,3))
subplot(212)
> > > > > > plot(t,B(1:timeperiods,i),'Color',rand(1,3))
> > > end

you might see it separate on two subplots

i think this should do :)

Subject: Plotting multiple lines on the same graph, different color

From: Dili Sam

Date: 12 Nov, 2012 06:00:23

Message: 5 of 5

Hi,
I have a bit of a similar prob. I need to get different colours or line styles for the multiple lines in the graph plotted by the following two for loops.
b=[0.3:0.05:0.6];
for j=1:length(b);
c=(a/b(j))-(1/R)*(n*vc*scz);
z=[0:10:560];
for i=1: length (z);
syms x;
Srr_conc= (a/b(j))-c*(exp(-T*b(j)*x));
S_bond = a-b(j)*(Srr_conc); %f is the bond stress at any level z from bottom
g = 0;
height=z(i);
Steel_stv(i)= -((2* rin)/( rout^2- rin^2))*int(S_bond, g, height);
Srr_conc2= (a/b(j))-c*(exp(-T*b(j)*z(i)));
Steel_epsv(i)=(1/Es)*( Steel_stv(i) +vs*(rin/(rout-rin))* Srr_conc2);
Conc_stv(i)= scz+rho*(- Steel_stv(i));
Conc_epsv(i)=(1/Ec)*( Conc_stv(i) -2*vc*Srr_conc2);
end
figure (2)
plot(z, Steel_epsv)
hold on
end
figure (2)
title('Steel vertical strains')
xlabel('Height from the bottom of column(mm)')
ylabel('Vertical strain (ยต?)')
legend('b_1=0.3','b_2=0.35','b_3=0.4','b_4=0.45','b_5=0.5','b_6=0.55','b_7=0.6')

Can someone please help?
Thanks in advance.

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us