matrix - How to sum values among matrices of structures under certain conditions in Matlab? -


i new in matlab , not familiar array of matrices. have number of matrices nx6:

<26x6 double> <21x6 double> <27x6 double> <36x6 double> <29x6 double> <30x6 double>  .... 

each matrix of type:

>> matrix{1,1}    b   c   d    e                  f 1   2   6   223  735064.287500000   f11 2   3   6   223  735064.288194445   f12 3   4   6   223  735064.288888889   f13 4   5   6   223  735064.290277778   f14  >> matrix{2,1}    b   c   d    e                  f 1   2   6   223  735064.700694445   f21 2   3   6   223  735064.701388889   f22 3   4   6   223  735064.702083333   f23 4   5   6   223  735064.702777778   f24  >> matrix{3,1}    b   c   d    e                  f 1   2   7   86  735064.3541666666   f31 2   3   7   86  735064.3548611112   f32 3   4   7   86  735064.3555555555   f33 4   5   7   86  735064.3562499999   f34 5   6   7   86  735064.702777778    f35  >> matrix{4,1}    b   c   d    e                  f 1   2   7   86   735064.3569444444  f41 2   3   7   86   735064.3576388888  f42 3   4   7   86   735064.3583333333  f43 4   5   7   86   735064.3590277778  f44 5   6   6   86   735064.702777778   f45 

where e , f dates in datenum format. f time difference.

considering matrices @ once, sum values of column f among matrices have equal values in columns a, b, d.

for each value of column d (the number of bus), obtain new matrix following one:

a   b   c   d    h 1   2   6   223  f11+f21 2   3   6   223  f12+f22 3   4   6   223  f13+f23 4   5   6   223  f14+f24     b   c   d   h 1   2   7   86  f31+f41 2   3   7   86  f32+f42 3   4   7   86  f33+f43 4   5   7   86  f34+f44 5   6   7   86  f35+f45 

thank in advance help!

this approach should started. suggested setting matrix stores comparison between columns 1,2 , 4. based on matrix can generate output matrix. saves nested if statements , checks in loop.
here's example (please note changed row 3 of matrix{1,1}):

matrix{1,1} = [ ...  1   2   6   223  735064.287500000   1; 2   3   6   223  735064.288194445   2; 3   4   6   223  735064.288888889   3; 4   5   6   223  735064.290277778   4];  matrix{2,1} = [ ...  1   2   6   223  735064.700694445   10; 2   3   6   223  735064.701388889   10; 2   4   6   223  735064.702083333   10; 4   5   6   223  735064.702777778   10];  comp = matrix{1,1}(:,[1:2 4])==matrix{2,1}(:,[1:2 4]);  = 1;  i=1:size(matrix{1,1},1)     if sum(comp(i,:)) == 3         sum{1,1}(a,1:5) = matrix{1,1}(i,1:5);         sum{1,1}(a,6) = matrix{1,1}(i,6) + matrix{2,1}(i,6);         = + 1;     end end 

the matrix comp stores 1 each element same in matrix{1,1} , matrix{2,1} when comparing columns 1, 2 , 4.
reduces if-statement check if elements in row agree (hence sum == 3). if condition satisfied, new matrix generated (sum{1,1}) sums entries in column 6, in case:

 sum{1,1}(:,6) =        11      12      14 

Comments