How to vectorize this code?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Jan
el 26 de Oct. de 2014
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.
Respuestas (1)
Guillaume
el 26 de Oct. de 2014
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 comentarios
Ver también
Categorías
Más información sobre Matrix Indexing en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!