Plotting matrix columns

조회 수: 163 (최근 30일)
Mark
Mark 2011년 5월 9일
댓글: mayank awasthi 2021년 6월 14일
I was able to do this in the past but forgot how I did it. Starting with a 2D matrix I was able to plot it with the first column as the X axis and generate individual sub plots of the remanining columns. Each column was its own plot with the 1st column as the X axis. A loop could do this but I seem to remember it was a simple command that put multiple plots in one figure window. Do I need to plot this as3D surface and then extract slices from the figure?
  댓글 수: 1
Helga Gomes
Helga Gomes 2015년 5월 9일
Hi, This is exactly the situation that I have and if i wasnt such a novice to Matlab I probably would have figured it out but I cant seem to. I too have the first column in excel which I want to use as my X axis and the next few as my Y axis. I want to be able to plot individual sub plots (different plots as jpeg or any other format) with my 1st column as my X axis every time but I want the Y axis to change as the remaining cols. I would like this to be a loop. but i dont know how to start by reading my xls or asci format file and then adding the loop.

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

답변 (4개)

Sean de Wolski
Sean de Wolski 2011년 5월 9일
doc hold
To plot multiple thingies
figure;
hold on
for ii = 1:10
plot(matrix(:,ii))
end
  댓글 수: 1
Sara Nouri
Sara Nouri 2020년 3월 28일
thank you.

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


Fangjun Jiang
Fangjun Jiang 2011년 5월 9일
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
Mark
Mark 2011년 5월 9일
This is similar to what I need. The command was able to make the multiple plots without having to manually request each coloumn or use a loop.
Fangjun Jiang
Fangjun Jiang 2011년 5월 9일
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);

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


Stephen23
Stephen23 2015년 5월 9일
편집: Stephen23 2015년 5월 9일
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
MOHAMED AMINE ZOUHRI
MOHAMED AMINE ZOUHRI 2020년 6월 19일
Thanks Stephen
mayank awasthi
mayank awasthi 2021년 6월 14일
Hello, Thanks for the simple solution but can you please inform me how can I put legends in this. And what if we have more Y columns.

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


Nina
Nina 2017년 9월 18일
Hi all, I have a question regarding the surface plotting. I have a matrix, where the first row is my x direction and the first column is my y direction. The values in between are the velocities of each point. Based on this matrix I want to create a 3D plot, where one axis is my x-direction, the second axis is my y-direction and the third axis is the velocity changes. Does anybody have an idea how should I do this?
  댓글 수: 2
KL
KL 2017년 9월 18일
something like
[X,Y] = meshgrid(your_data(1,2:end),your_data(2:end,1))
contour(X,Y,your_data(2:end,2:end))
Nina
Nina 2017년 9월 19일
Thank you so much for your answer. It worked :)

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

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by