Asked by Thar
on 21 Mar 2015

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!

Answer by the cyclist
on 21 Mar 2015

Accepted Answer

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

Thar
on 21 Mar 2015

Is there way to write the number of the day on the graph?

Thank you!

Konstantinos Sofos
on 21 Mar 2015

use after plot...

title(num2str(uniqueDays(nd)))

Sign in to comment.

Answer by Konstantinos Sofos
on 21 Mar 2015

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

Sign in to comment.

Opportunities for recent engineering grads.

Apply Today
## 2 Comments

## Geoff Hayes (view profile)

Direct link to this comment:https://ch.mathworks.com/matlabcentral/answers/184350-how-to-plot-different-figures-from-the-same-matrix#comment_273630

## Thar (view profile)

Direct link to this comment:https://ch.mathworks.com/matlabcentral/answers/184350-how-to-plot-different-figures-from-the-same-matrix#comment_273632

Sign in to comment.