Construct product of matrices without for loop
Show older comments
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 Comments
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
on 12 Aug 2013
This appears to duplicate part of http://www.mathworks.co.uk/matlabcentral/answers/84498-construct-product-of-matrices-without-for-loop
Accepted Answer
More Answers (0)
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!