Construct product of matrices without for loop
显示 更早的评论
Hi, everyone:
Suppose A is a 2 by 2 by N matrix, is it possible to construct a matrix B, such that:
B=[Prod(A)_1^{N-n}, Prod(A)_2^{N-n}, ... , Prod(A)_{N-n}^{N-n};
Prod(A)_1^{N-n+1}, Prod(A)_2^{N-n+1}, ... , Prod(A)_{N-n}^{N-n+1};
. . . .
. . . .
Prod(A)_1^N, Prod(A)_2^N, ... , Prod(A)_{N-n}^N]
where Prod(A)_m^n = A(:,:,m)*A(:,:,m+1)*A(:,:,m+2)* ... * A(:,:,n); (1 << n << N)
without any loop?? (maybe use arrayfun? cellfun?)
because for loop is too slow for me.
Thanks
2 个评论
When you claim, that the FOR loop is too slow, do not hope, that CELLFUN or ARRAY is faster. But use loops internally also, but have the additional overhead for calling Matlab from the Mex level.
When your code is too slow for your needs, you could post the relevant part of it and ask, if somebody knows improvements. For testing the ideas before answering, provided test data are very useful.
"n" appears twice with different meaning in your example. How large is it in the definition of B and what are typical sizes of N?
Walter Roberson
2013-8-12
This appears to duplicate part of http://www.mathworks.co.uk/matlabcentral/answers/84498-construct-product-of-matrices-without-for-loop
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!