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에서 Operators and Elementary Operations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!