# Plotting matrix columns

650 views (last 30 days)

Show older comments

##### 1 Comment

Helga Gomes
on 9 May 2015

### Answers (4)

Sean de Wolski
on 9 May 2011

doc hold

To plot multiple thingies

figure;

hold on

for ii = 1:10

plot(matrix(:,ii))

end

Fangjun Jiang
on 9 May 2011

Example like this?

a=[1:10;sin(1:10);cos(1:10)]';

subplot(2,1,1);plot(a(:,1),a(:,2));

subplot(2,1,2);plot(a(:,1),a(:,3));

##### 2 Comments

Fangjun Jiang
on 9 May 2011

I am not aware a built-in function to do that. Is it possible that you were using a customized function built upon subplot()? Such as:

function AutoSubPlot(a)

N=size(a,2);

if N<2,error('incorrect dimension');end

for i=1:N-1

subplot(N-1,1,i);plot(a(:,1),a(:,i+1));

end

Then, you can all this AutoSubPlot() function:

a=[1:10;sin(1:10);cos(1:10);sin(1:10);cos(1:10)]';

AutoSubPlot(a);

Stephen
on 9 May 2015

Edited: Stephen
on 9 May 2015

It is not clear if you really require subplots, and the other answers are mixed on this too... If the plots are to be on the same axes, then this is very easy, as plot already plots column-wise:

>> A = [1,2,3,4,5; 1,0,1,2,1; 2,1,0,1,2].'

A =

1 1 2

2 0 1

3 1 0

4 2 1

5 1 2

>> plot(A(:,1), A(:,2:end)) % first column is the x-values

produces this figure:

##### 3 Comments

mayank awasthi
on 14 Jun 2021

Nina
on 18 Sep 2017

##### 2 Comments

### See Also

### Categories

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!