Fast function application

조회 수: 2 (최근 30일)
Mateusz
Mateusz 2011년 9월 29일
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