I have a problem which I hope contributors can help me solve. I think it is best just to provide a working example:
I have two cells both of which consist of the same number of matrices (the result of reading a series of data files followed by some loop calculations). Each matrix is a column of decimal year days followed by a series of columns of data. Here is the dummy data:
A = [ 186.356 1 2 3 4;186.364 2 3 4 5;186.372 3 4 5 6]
B = [ 187.356 1 2 3 4;187.364 2 3 4 5;187.372 3 4 5 6]
C = [ 188.356 1 2 3 4;188.364 2 3 4 5;188.372 3 4 5 6]
x = {A,B,C}
D = [ 186.3568 1 2 3 4; 186.3576 2 3 4 5; 186.3584 3 4 5 6; 186.3592 4 5 6 7; 186.36 5 6 7 8; 186.3608 6 7 8 9; 186.3616 7 8 9 10; 186.3624 8 9 10 11; 186.3632 9 10 11 12; 186.364 10 11 12 13; 186.3648 11 12 13 14; 186.3656 12 13 14 15]
E = [ 187.3568 1 2 3 4; 187.3576 2 3 4 5; 187.3584 3 4 5 6; 187.3592 4 5 6 7; 187.36 5 6 7 8; 187.3608 6 7 8 9; 187.3616 7 8 9 10; 187.3624 8 9 10 11; 187.3632 9 10 11 12; 187.364 10 11 12 13; 187.3648 11 12 13 14; 187.3656 12 13 14 15]
F = [ 188.3568 1 2 3 4; 188.3576 2 3 4 5; 188.3584 3 4 5 6; 188.3592 4 5 6 7; 188.36 5 6 7 8; 188.3608 6 7 8 9; 188.3616 7 8 9 10; 188.3624 8 9 10 11; 188.3632 9 10 11 12; 188.364 10 11 12 13; 188.3648 11 12 13 14; 188.3656 12 13 14 15]
y = {D,E,F}
My intention is to sum the data columns contained within both x and y. However you can see that the resolution of the data in y is much higher than x therefore I would first like to average the data in y based upon the timesteps of x.
As an example the first time period which matches between x and y correspond to row 1 in matrix A but only the first 10 rows in matrix D. The sum of the first row in A is 10:
sumA = sum(A(1,2:end),2)
and the average of the first 10 rows in D is
sumD = sum(mean(D(1:10,2:end)),2)
resulting in a total of 38.
This is a simple example; I have many rows of data in two large cells. I suspect I need to extract the data from the cells, loop through the data whilst rewriting to another cell of the same dimensions as the first two cells, x and y but am at a loss as to where to start. Any help would be great.
Edit
In looking to clarify my problem I realise I made a mistake in the original question. This is no doubt the cause of the confusion.
Everything above is correct however the sum of the first 10 rows of D:
sumD = sum(mean(D(1:10,2:end)),2)
sumD =
28
should actually be added to the sum of the second row in A:
sumA = sum(A(2,2:end),2)
sumA =
14
This is because all the values in rows 1-10 of column 1 in matrix D are larger than the the value in row 1 and column 1 of matrix A but smaller than or equal to row 2 and column 2 of matrix A. It might be easier if increase the dummy data in matrix D:
D = [ 186.3568 1 2 3 4; 186.3576 2 3 4 5; 186.3584 3 4 5 6; 186.3592 4 5 6 7; 186.36 5 6 7 8; 186.3608 6 7 8 9; 186.3616 7 8 9 10; 186.3624 8 9 10 11; 186.3632 9 10 11 12; 186.364 10 11 12 13; 186.3648 11 12 13 14; 186.3656 12 13 14 15; 186.3664 13 14 15 16; 186.3672 14 15 16 17; 186.368 15 16 17 18; 186.3688 16 17 18 19; 186.3696 17 18 19 20; 186.3704 18 19 20 21; 186.3712 19 20 21 22; 186.372 20 21 22 23]
Now the result would be a two value vector. The first value would be 28+14, the result of the sum of the second row in A (or sumA) and the sum of the mean of the first 10 rows of data in matrix D (or sumD). The second value would the sum of the third row in A, lets say sumA2:
sumA2 = sum(A(3,2:end),2)
sumA2 =
18
and sumD2:
sumD2 = sum(mean(D(11:end,2:end)),2)
sumD2 =
68
sumA2+sumD2
ans =
86
I would like this process to be automated so that I can go through each matrix in the cell. i.e. if I start with cells x and y with dims:
x =
[300x5 double] [300x5 double] [300x5 double]
y =
[2000x5 double] [2000x5 double] [2000x5 double]
I would like the result to be
z =
[300x1 double] [300x1 double] [300x1 double]
I am not sure if that makes things any clearer but lets see!