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

조회 수: 45 (최근 30일)
Madania Nia
Madania Nia 2020년 5월 31일
댓글: Earth Sugandhi 2021년 2월 3일
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!

답변 (3개)

madhan ravi
madhan ravi 2020년 5월 31일
plot(matrix)

Aquatris
Aquatris 2020년 5월 31일
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
  댓글 수: 6
madhan ravi
madhan ravi 2020년 5월 31일
편집: madhan ravi 2020년 5월 31일
And ofcourse the original question is answered by Aquatris without a doubt.
Earth Sugandhi
Earth Sugandhi 2021년 2월 3일
okay, this is good but I have very large array, and using for loop is taking time, how can we do it without for loops?

댓글을 달려면 로그인하십시오.


Prasad Reddy
Prasad Reddy 2020년 5월 31일
% 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
A=[] % your matrix.
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.
  댓글 수: 3
madhan ravi
madhan ravi 2020년 5월 31일
plot(t,A(:,i)) % because he missed one “)” % at the end of that line
Madania Nia
Madania Nia 2020년 5월 31일
ah i see, i didnt check it :D
thank you so much

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

태그

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by