How can we run a loop to stack data for each day in both years (use 12 hours in each day)?

2 次查看(过去 30 天)
I have a matrix with 4 columns in a mat file
we have two-year data and each day has 12 sections.
How can we run a loop to stack data for each day in both years (use 12 hours in each day)?
for e.g
% this is how data looks like
year day NCF Hour
2018 282 3001x1 double 1
2018 282 3001x1 double 2
2018 282 3001x1 double 3
2018 282 3001x1 double 4
2018 282 3001x1 double 5
2018 282 3001x1 double 6
2018 282 3001x1 double 7
2018 282 3001x1 double 8
2018 282 3001x1 double 9
2018 282 3001x1 double 10
2018 282 3001x1 double 11
2018 282 3001x1 double 12
2018 283 3001x1 double 1
2018 283 3001x1 double 2
2018 283 3001x1 double 3
2018 283 3001x1 double 4
2018 283 3001x1 double 5
2018 283 3001x1 double 6
2018 283 3001x1 double 7
2018 283 3001x1 double 8
2018 283 3001x1 double 9
2018 283 3001x1 double 10
2018 283 3001x1 double 11
2018 283 3001x1 double 12
... ... ....... ...
... ... ....... ...
2019 365 ............... 12

回答(1 个)

Mohammad Sami
Mohammad Sami 2021-3-17
编辑:Mohammad Sami 2021-3-17
I am assuming this is a struct. Also assuming that data in NCF is the same size.
%convert to table.
% mydata = struct();
t = struct2table(mydata);
% make sure that the data is sorted by year, day, hour
t = sortrows(t,{'year','day','hour'},'ascend');
ncf = horzcat(t.NCF{:})';
% assuming you want the year, day, hour in the same way
n = 3001
y = repelem(t.year,n);
d = repelem(t.day,n);
h = repelem(t.hour,n);
  3 个评论

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Dates and Time 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by