How to vectorize this code?
1 回表示 (過去 30 日間)
古いコメントを表示
I try to use bsxfun, but maybe it does not suit this purpose.
C = bsxfun(@function,A(AIterator),cell2mat(B(BIterator)))
A is n*6, where the iterator runs on n, and B is a cell with 3*3 doubles (length m). Thanks for the help.
5 件のコメント
Jan
2014 年 10 月 26 日
I'm deeply confused. What is the meaning of:
The function calculates an array based on the 6; and 3*3 doubles.
?? Please post a minimal running example, which demonstrates your problem.
回答 (1 件)
Guillaume
2014 年 10 月 26 日
bsxfun can only return matrices, not cell arrays, and only operates on matrices as well. If your output has to be a cell array, you can't use bsxfun.
Without knowing more about function, the best that you could do is vectorise the inner loop with:
outM(AIterator, :) = cellfun(@(b) function(A(AIterator, :), cell2mat(b), B, 'UniformOutput', false);
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Matrix Indexing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!