|
"Timothy Hilton" wrote in message <jna31g$cq1$1@newscl01ah.mathworks.com>...
> groups = nominal( {'a', 'a', 'a', 'a', 'b', 'b', 'b', 'b'; ...
> '1', '2', '1', '2', '1', '2', '1', '2' } );
> data = rand( 10, 8 );
>
> I need the row-wise mean of each combination of type/depth I could solve this
> example with
>
> [ mean( data( :, [1, 3] ), 2 ), ...
> mean( data( :, [2, 4] ), 2 ), ...
> mean( data( :, [5, 7] ), 2 ), ...
> mean( data( :, [6, 8] ), 2 ) ];
>
> I have a number of sites where the number of types and depths varies as well as
> their relative column positions, so I'm trying to figure out a vectorized
> solution to identify groups and aggregate.
- - - - - - - - -
Try this:
[~,~,p] = unique(groups.','rows');
[I,J] = ndgrid(1:size(data,1),p);
S = [I(:),J(:)];
A = accumarray(S,data(:))./accumarray(S,1);
Roger Stafford
|