필터 지우기
필터 지우기

Ask for rearrange daily data from multiple columns to a single row

조회 수: 1 (최근 30일)
Phat Pumchawsaun
Phat Pumchawsaun 2018년 1월 4일
Hi,
I have the original matrix named A containing daily river flows with 5-year records (2006-2010) so that the dimension of the matrix is 155x12 (31 calendar days in rows and 12 months in column).
Matrix A
DATE JAN FEB.........DEC
1-1-2006
1-2-2006
.
.
31-12-2010
Next step, I would like to rearrange data to be dimension of 1860x1 ranging from 1-Jan-2006 to 31-Dec-2010 and I used the following codes;
[num] = xlsread('A.xlsx');
z = num(:,2:end);
z2006 = z(1:31,1:12);
z2006_2 = reshape(z2006,372,1,[]);
z2007 = z(32:62,1:12);
z2007_2 = reshape(z2007,372,1,[]);
z2008 = z(63:93,1:12);
z2008_2 = reshape(z2008,372,1,[]);
z2009 = z(94:124,1:12);
z2009_2 = reshape(z2009,372,1,[]);
z2010 = z(125:155,1:12);
z2010_2 = reshape(z2010,372,1,[]);
Q = zeros(1860,1);
Q(:,:) = [z2006_2;z2007_2;z2008_2;z2009_2;z2010_2];
Overall, the code is fine and I can create the new matrix I really want. However, I just concern if I would like to manage the data with a longer recorded data such as 20 years so that this code may consume a lot of time since I have to write code manually. Therefore, can anyone help me to find a better code such as using for-loop, etc. that I can deal with many years of recorded data?
Thanks
Phat

답변 (1개)

Emmanouil Tzorakoleftherakis
Emmanouil Tzorakoleftherakis 2018년 1월 8일
Hi Phat,
you could try something along the following lines:
yrs = 5; % number of years
Q = zeros(yrs*31*12, 1);
for i = 1:yrs
Q((i-1)*372+1:i*372) = reshape(z((i-1)*31+1:i*31,:), 372,1);
end

카테고리

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