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

1 vue (au cours des 30 derniers jours)
Phat Pumchawsaun
Phat Pumchawsaun le 4 Jan 2018
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

Réponses (1)

Emmanouil Tzorakoleftherakis
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

Catégories

En savoir plus sur Dates and Time dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by