Fast function application

2 次查看(过去 30 天)
Hi,
Let a be n-dimensional vector, B n-by-n dimensional matrix, f(a, b) - binary function that operates on two vectors, and returns scalar as a result. Is there fast way (no-loops) to implement application of this function to vector a and every column of matrix B? More precisely forall_j r(j) = f(a, B(:, j))?
  1 个评论
Mateusz
Mateusz 2011-9-29
I think I cannot repmat vector 'a' since f has to work explicitly on vectors.

请先登录,再进行评论。

采纳的回答

Walter Roberson
Walter Roberson 2011-9-29
These days, "no loops" is not necessary any faster.
You can use
arrayfun(@(K) f(a,B(:,K)), 1:size(B,2))
but that will probably not be any faster than a loop.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by