I require the vectors of sums for the sub-arrays along an array of arbitrary dimensions. The following question is related to the topic on arrays of arbitrary dimensions posted here. Given a j-dimensional regular array:
j = 2;
d = 5;
rng('default');
Array = rand( repmat( d , 1 , j ) ) ;
I require the vectors of sum for subarrays along the dimensions of , followed by subsubarrays, etc. The simple example of matrix is: ArraySum = cell( 2 , 1 ) ;
for m = 1:2
ArraySum{ m } = reshape( sum( Array , m ) , [] , 1 ) ;
end
where is a cell array containing two vectors for the sums across each of the respective dimensions of . The desired function for the case is:
ArraySum = cell( 3 , 1 ) ;
ArraySumArray = [];
for m = 1:3
for n = 1:2
ArraySum{ m }{ n } = round( reshape( sum( reshape( sum( Array , m ) , d , d ) , n ) , d , 1 ) , 10 ) ;
ArraySumArray = [ ArraySumArray ArraySum{ m }{ n } ] ;
end
end
ArraySumArray = unique(ArraySumArray','rows')' ;
for m = 1:3
ArraySum{ m } = ArraySumArray( : , m ) ;
end
where now contains three vectors, asis three-dimensional. Note that cases for must account for the loss in dimensionality with each result of the function, where . There are also repeating vectors with each valid combination of sums that must also be removed. This is dealt with using the function. The problem now extends to all cases, where a j-dimensional regular array yields j unique vectors of sums in the manner desribed above. This implies the pseudo-code structure, albeit ineloquently:
ArraySum = cell( j , 1 ) ;
ArraySumArray = [];
for m(1)) = 1:j
...
for m(j-1) = 1:2
ArraySum{ m(1) }...
ArraySumArray = [ ArraySumArray ArraySum{ m(1) }...
end
...
end
ArraySumArray = unique(ArraySumArray','rows')' ;
for m = 1:j
ArraySum{ m } = ArraySumArray( : , m ) ;
end
Does there exist a valid means of obtaining the vectors of sums in the manner described above for an array of arbitrary dimensions in MATLAB?