Got Questions? Get Answers.
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

Subject: Plotting multiple lines on the same graph

From: Ulrik Nash

Date: 14 Oct, 2011 19:22:27

Message: 1 of 2

Hello,

I am trying to plot the content of column vectors in matrix A on the same graph. I was hoping the following would work, but only the line for the last vector remains:

for i = numel(A(1,:))
y = A(1:10,i);
x = 1:10;
plot(x,y)
hold all
end

What would be a better way to achive my aim?

Regards,

Ulrik.

Subject: Plotting multiple lines on the same graph

From: Diego Torquemada

Date: 14 Oct, 2011 19:40:10

Message: 2 of 2

On Oct 14, 2:22 pm, "Ulrik Nash" <u...@sam.sdu.dk> wrote:
> Hello,
>
> I am trying to plot the content of column vectors in matrix A on the same graph. I was hoping the following would work, but only the line for the last vector remains:
>
> for i = numel(A(1,:))
> y = A(1:10,i);
> x = 1:10;
> plot(x,y)    
> hold all
> end
>
> What would be a better way to achive my aim?
>
> Regards,
>
> Ulrik.

Simply do the following:

x = 1:10;
A = rand(10,5);
plot(x,A)

As you see this plots five lines, each corresponds to a column of A

Regards,

Diego

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