Summation and array indexes
显示 更早的评论
I am trying to write a function for an optimisation routine that requires the (total) summation of a matrix divided element by element by a second matrix, where the second matrix has a third dimension returning a vector the size of that third dimension.
i.e. something along the lines of a(1:n) = sum(sum(A./B(:,:,1:n))
which doesn't work. Any ideas?
Thanks
2 个评论
Adam
2014-10-13
Can you give a simple example of inputs A and B?
采纳的回答
更多回答(2 个)
Adam
2014-10-14
c = bsxfun( @rdivide, A, B );
a = squeeze( sum( sum( c ) ) );
should give the answer you want. Obviously you could do it in one line if you prefer.
Roger Stafford
2014-10-14
sum(A(:))./sum(sum(B,1),2)
类别
在 帮助中心 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!