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

2 views (last 30 days)
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

Answers (1)

Mohammad Sami
Mohammad Sami on 17 Mar 2021
Edited: Mohammad Sami on 17 Mar 2021
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 Comments
AA
AA on 17 Mar 2021
We want to stack 12 hours in one day
For example output should be only for 282 day in 2018, not 12

Sign in to comment.

Categories

Find more on Dates and Time in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!