How can I separate individual years from a timetable?

Hi!
I have one table that contains 764 rows with different year's data point from 1984 to 2022. For example, row 1 to 8 are for 1984, row 9 to 14 are for 1985, row 15 to 24 are for 1986 and so on.
Can anyone please tell me how to create a cell array where I can have the indices for the individual year?
i.e., {year_list} = {[1:8];[9:14];[15:24],....} etc.
I have added the table in this question. Any feedback will be greatly appreciated!!

 Akzeptierte Antwort

Stephen23
Stephen23 am 6 Mär. 2023
Bearbeitet: Stephen23 am 6 Mär. 2023
S = load('DateStamp.mat')
S = struct with fields:
DateStamp: [764×3 table]
T = S.DateStamp
T = 764×3 table
date x_CloudCover landsat __________ ____________ _____________ 1984-05-02 0.12 {'landsat_5'} 1984-06-03 18.49 {'landsat_5'} 1984-06-19 0 {'landsat_5'} 1984-09-23 1.49 {'landsat_5'} 1984-10-09 47.1 {'landsat_5'} 1984-10-25 7.27 {'landsat_5'} 1984-11-10 46.36 {'landsat_5'} 1984-11-26 0.08 {'landsat_5'} 1985-01-29 0.11 {'landsat_5'} 1985-04-19 71.61 {'landsat_5'} 1985-06-22 1.53 {'landsat_5'} 1985-08-09 0 {'landsat_5'} 1985-10-12 0 {'landsat_5'} 1985-10-28 0 {'landsat_5'} 1986-01-16 16.37 {'landsat_5'} 1986-02-01 43.73 {'landsat_5'}
[G,Y] = findgroups(T.date.Year);
X = arrayfun(@(x)find(x==G), 1:max(G), 'uni',0);
These are the years:
Y
Y = 39×1
1984 1985 1986 1987 1988 1989 1990 1991 1992 1993
and the corresponding indices:
X
X = 1×39 cell array
{8×1 double} {6×1 double} {10×1 double} {12×1 double} {12×1 double} {14×1 double} {9×1 double} {12×1 double} {14×1 double} {14×1 double} {12×1 double} {14×1 double} {8×1 double} {9×1 double} {11×1 double} {25×1 double} {23×1 double} {26×1 double} {24×1 double} {25×1 double} {23×1 double} {28×1 double} {25×1 double} {24×1 double} {29×1 double} {22×1 double} {24×1 double} {23×1 double} {10×1 double} {23×1 double} {28×1 double} {30×1 double} {32×1 double} {24×1 double} {24×1 double} {30×1 double} {26×1 double} {28×1 double} {23×1 double}
X{1:3}
ans = 8×1
1 2 3 4 5 6 7 8
ans = 6×1
9 10 11 12 13 14
ans = 10×1
15 16 17 18 19 20 21 22 23 24
See also:

4 Kommentare

Hi! Thank you @Stephen23. This is a cool way to list the indices, and I didn't know about it. But that is not what I was looking for. I want to prepare the count for individual years as I mentioned in the question -
i.e., {year_list} = {[1:8];[9:14];[15:24],....} etc.
Because I will have to feed the number of the arrays in my later calculation. Any suggestion from you will be very helpful in thi regard!
Excellent! Thanks
Hi @Stephen23, can you please give me an idea on how can I show an observation count for individual year?
For example, 1984 had 8 observations, 1985 has 6, 1987 has 10 and so on. I am imagining a histogram where X axis will represent the year and Y-axis is for observation frequency. But I am not sure if it is possible to plot. Then I might have to look other way.
S = load('DateStamp.mat');
T = S.DateStamp
T = 764×3 table
date x_CloudCover landsat __________ ____________ _____________ 1984-05-02 0.12 {'landsat_5'} 1984-06-03 18.49 {'landsat_5'} 1984-06-19 0 {'landsat_5'} 1984-09-23 1.49 {'landsat_5'} 1984-10-09 47.1 {'landsat_5'} 1984-10-25 7.27 {'landsat_5'} 1984-11-10 46.36 {'landsat_5'} 1984-11-26 0.08 {'landsat_5'} 1985-01-29 0.11 {'landsat_5'} 1985-04-19 71.61 {'landsat_5'} 1985-06-22 1.53 {'landsat_5'} 1985-08-09 0 {'landsat_5'} 1985-10-12 0 {'landsat_5'} 1985-10-28 0 {'landsat_5'} 1986-01-16 16.37 {'landsat_5'} 1986-02-01 43.73 {'landsat_5'}
[G,Y] = findgroups(T.date.Year);
N = accumarray(G,ones(size(G)));
bar(Y,N)

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Community Treasure Hunt

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

Start Hunting!

Translated by