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
AA
AA 2021년 3월 17일
We want to stack 12 hours in one day
For example output should be only for 282 day in 2018, not 12

댓글을 달려면 로그인하십시오.

카테고리

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