How can I separate individual years from a timetable?

조회 수: 5 (최근 30일)
Ashfaq Ahmed
Ashfaq Ahmed 2023년 3월 6일
댓글: Stephen23 2023년 3월 7일
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에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by