how to plot different figures from the same matrix

조회 수: 2 (최근 30일)
Thar
Thar 2015년 3월 21일
댓글: Konstantinos Sofos 2015년 3월 21일
Hi!
I have a matrix with 1376x3 dimensions. First column is the day, second the time and third my measurements. The matrix is:
8 7.56 316
8 8.45 319.56
8 10.78 317.4
9 12.76 323.98
9 14.27 356.89
10 13.45 346.12
10 14.2 312.43
and so on, until the day 365. (some days are missing).
I want to plot the second and third columns for each day separately.
Any ideas?
Thank you!
  댓글 수: 2
Geoff Hayes
Geoff Hayes 2015년 3월 21일
Thodoris - do you want all of this data on one figure or do you want one figure for each day of the year? I can't imagine you wanting up to 365 figures for all of this data so please describe what you would like to obtain and what you have attempted so far.
Thar
Thar 2015년 3월 21일
I want one figure for each day of the year. But i can't separate and keep the data for each day.

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

채택된 답변

the cyclist
the cyclist 2015년 3월 21일
Try this
D = [
8 7.56 316
8 8.45 319.56
8 10.78 317.4
9 12.76 323.98
9 14.27 356.89
10 13.45 346.12
10 14.2 312.43]
uniqueDays = unique(D(:,1));
numberUniqueDays = numel(uniqueDays);
for nd = 1:numberUniqueDays
indexToThisDay = D(:,1)==uniqueDays(nd);
figure
plot(D(indexToThisDay,2),D(indexToThisDay,3))
end
  댓글 수: 2
Thar
Thar 2015년 3월 21일
Is there way to write the number of the day on the graph?
Thank you!
Konstantinos Sofos
Konstantinos Sofos 2015년 3월 21일
use after plot...
title(num2str(uniqueDays(nd)))

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

추가 답변 (1개)

Konstantinos Sofos
Konstantinos Sofos 2015년 3월 21일
Hi Thodoris,
As i understood in each day you (may) have more that one timestamps of measurements and you want a figure (or plot??) for each corresponding day with its measurements. So i imagine that your basic problem is an indexation problem. (Are your days format as you described i.e. 1,2,3... or in a date number format?)
Assuming the matrix that you gave us
A =
8.0000 7.5600 316.0000
8.0000 8.4500 319.5600
8.0000 10.7800 317.4000
9.0000 12.7600 323.9800
9.0000 14.2700 356.8900
10.0000 13.4500 346.1200
10.0000 14.2000 312.4300
you can find the indexation of the days as
idx=find(diff(A(:,1)) == 1) + 1; % day indexation
idx = [1;idx;length(A)]; % consider the start and the end of the time period
%plotting : Create a figure for each day
for i=1:numel(idx)-1
figure
x = A(idx(i):idx(i+1)-1,2);
y = A(idx(i):idx(i+1)-1,3);
plot(x,y,'r*-')
end
So this will give you 365 figures...is this really that you want?
Regards

카테고리

Help CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by