Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Matlab : Plot each line of a matrix as a function of its index

I would like to create a plot with several lines, each corresponding to a row at a given matrix.

To be more elaborate, I have got a matrix M where each row represents a value that is changing along the columns. I would like to plot this change as a function of the column index to each of the rows, so to plot (e.g) the first rowI should :

plot(M(1,:));

The thing is, I would like to plot all the rows. Of course I could iterate over them, hold and plot the current one:

(plot(M(i,:))

but I'm wondering if there's a simple command or a single-liner that would do it.

I have tried plotmatrix but without much success regarding the desirable results.

Thanks!

like image 462
Ohad Dan Avatar asked Jan 15 '23 20:01

Ohad Dan


1 Answers

Have you tried plot(M')?

From the first paragraph of the documentation of plot:

plot(Y) plots the columns of Y versus the index of each value when Y is a real number.

like image 56
Tim Avatar answered Jan 31 '23 08:01

Tim