|
"james bejon" <jamesbejon@yahoo.co.uk> wrote in message <hpr0vf$fl0$1@fred.mathworks.com>...
> I'm probably missing something obvious here, but suppose I have the following
>
> r = rand(4, 5, 3, 9, 10);
>
> and I want to create, say, a (1 x 5 x 1 x 9) matrix by summing dimensions 1, 3 and 5. I thought something like
>
> sum(r, [1, 3, 5])
>
> might do the job. But it doesn't. And
>
> sum(sum(sum(r, 1), 3), 5)
>
> seems a bit clumsy. Any suggestions?
Why not just create your own function which enables the first syntax
sumdims(r,[1,3,5])
function out=sumdims(r,dims)
out=r;
for i=1:length(dims)
out=sum(out,dims(i));
end
|