Miss Michi
Miss Michi

Reputation: 53

How to dynamically plot the columns of a matrix to one another?

mat = [1,2,1;2,4,6;3,6,9];
mat =

 1     2     1
 2     4     6
 3     6     9


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

I would like to know how it is done to plot the first column of mat to every other column of the matrix. But I don't want to do it like above mentioned. Is there a way to do it with any matrix with variable size.

Upvotes: 2

Views: 53

Answers (2)

Etienne Pellegrini
Etienne Pellegrini

Reputation: 748

You can use a simple for loop:

for i = 2:size(mat,2)
  plot(mat(:,1), mat(:,i));
  hold all
end

Upvotes: 2

Rafael Monteiro
Rafael Monteiro

Reputation: 4549

You can do it this way:

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

Upvotes: 4

Related Questions