# How to plot every column of matrix into a different graphic but in one figure

1 view (last 30 days)
Madania Nia on 31 May 2020
Edited: madhan ravi on 31 May 2020
i have a matix 13 x 4, i want that first column get plot in one graph, then plot 2nd column in another graph, so on until the 4th column. but every graphs must be plot in one figure. can anyone give me the solution of it using loop or "for" function? thank you!

madhan ravi on 31 May 2020
plot(matrix)

Aquatris on 31 May 2020
This might be what you are looking for
A = rand(13,4); % random 13x4 matrix
[r,c] = size(A); % get number of rows and columns of A
for i = 1:c % columns 1 to c
figure(1)
subplot(c,1,i),plot(A(:,i)) % plot the ith column in ith graph in figure(1)
%subplot(1,c,i),plot(A(:,i)) % alternative for horizontal layout
end

madhan ravi on 31 May 2020
Madania for that look at my solution .
Aquatris on 31 May 2020
If you want all columns in the same plot
plot(A)
would do the job.
madhan ravi on 31 May 2020
And ofcourse the original question is answered by Aquatris without a doubt.

Prasad Reddy on 31 May 2020
% let us suppose your matrix is A,and you want toplot all the columns of A with espect to dome other variable. You havent mentioned that variable in the question. i am considering it as ' t ' .
the code will be as follows.
clc
clear all
t=[] % the x axis variable. it should have same number of elements as of the elements in one column of A ie 13.
for i=1:4
plot(t,A(:,i)
hold on
end
% this code will work. message here if you find any difficulty. Give me a up thumb if this helps to you. Thanks.

Madania Nia on 31 May 2020
thank you for ur help. but, why it say "invalid expression" in plot part?
madhan ravi on 31 May 2020
plot(t,A(:,i)) % because he missed one “)” % at the end of that line
Madania Nia on 31 May 2020
ah i see, i didnt check it :D
thank you so much