Fast function application

1 view (last 30 days)
Mateusz
Mateusz on 29 Sep 2011
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 Comment
Mateusz
Mateusz on 29 Sep 2011
I think I cannot repmat vector 'a' since f has to work explicitly on vectors.

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 29 Sep 2011
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.

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!