Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

Using ordered list for plotting charts

조회 수: 2 (최근 30일)
Carlos Nogueira
Carlos Nogueira 2015년 5월 5일
마감: MATLAB Answer Bot 2021년 8월 20일
Hi guys!
I have a list of numbers as shown below. The problem is, I need plotting some charts using these data. You gonna notice that the first value of 5th column is 23, so I need to sweep all the rows which contains 23 in the 5th column and make a chart. After that, I go to the next one (28) and do the same. How could I do that? I have plenty of files which have different numbers of rows, for instance, the first file has 10 rows with 23 in the 5th column, but the last file could have 18 rows which has 23 in the 5th column. Please, I need your help and thank in advance! See ya!

답변 (1개)

Michael Haderlein
Michael Haderlein 2015년 5월 5일
Your question is a bit unclear. Do you struggle with loading the data, with sorting the data or with plotting the data? Plus, what kind of plot do you mean?
As loading this kind of files is pretty simple, I just want to refer to dlmread.
As I have just answered on another question with slightly similar content, I suggest to use arrayfun also here. Suppose data is the variable containing all the data (intuitive naming here).
figure, hold all
arrayfun(@(x) plot(data(data(:,5)==x,2)),unique(data(:,5)))
will plot the data of the second column over 1:n, while
figure, hold all
arrayfun(@(x) plot(data(data(:,5)==x,1),data(data(:,5)==x,2)),unique(data(:,5)))
will plot the data of the second column over the data of the first column. If you need another kind of plotting, just change the argument here.
  댓글 수: 4
Carlos Nogueira
Carlos Nogueira 2015년 5월 7일
Hi Michael! Yes, my plot should be the 6th column plotted against the 4th as you said. If I found a way to find out what would be the position of the last element repeated, I guess my problem would be solved. For instance, in the last picture I sent, the first element of 5th column is 23. In this file, it repeats up to 23th row (shaded in blue).
Michael Haderlein
Michael Haderlein 2015년 5월 8일
Well, if you just want the 6th column be plotted against the 4th (was just a random guess I must admit), simply change my upper suggestion to:
figure, hold all
arrayfun(@(x) plot(data(data(:,5)==x,4),data(data(:,5)==x,6)),unique(data(:,5)))
or, to make it clear:
indicatingColumn=5;
xColumn=4;
yColumn=6;
figure, hold all
arrayfun(@(x)plot(data(data(:,indicatingColumn)==x,xColumn),...
data(data(:,indicatingColumn)==x,yColumn)),...
unique(data(:,indicatingColumn)))

이 질문은 마감되었습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by