How can I separate individual years from a timetable?

3 次查看(过去 30 天)
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!!

采纳的回答

Stephen23
Stephen23 2023-3-6
编辑:Stephen23 2023-3-6
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 个评论
Ashfaq Ahmed
Ashfaq Ahmed 2023-3-7
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.
Stephen23
Stephen23 2023-3-7
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)

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Descriptive Statistics 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by