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

2 Ansichten (letzte 30 Tage)
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

Antworten (1)

Mohammad Sami
Mohammad Sami am 17 Mär. 2021
Bearbeitet: Mohammad Sami am 17 Mär. 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 Kommentare
AA
AA am 17 Mär. 2021
We want to stack 12 hours in one day
For example output should be only for 282 day in 2018, not 12

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Dates and Time finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by