2

I have an array A of size [m x n], a function f(array, a, b, c) and an array of variables [a1 b1 c1; a2 b2 c2; ... ak bk ck].

I want to get an array:

[f(A, a1, b1, c1); f(A, a2, b2, c2); ... f(A, ak, bk, ck)]

Is it an ellegant way to realize this in MATLAB without using cumbersome loop structure?

for i = 1:k
B(i) = f(A, a(i), b(i), c(i));
end

1 Answer 1

1

How about using arrayfun?
let P be the k by 3 matrix with parameters [a1 b1 c1;...' ak bk ck] then

B = arrayfun( @(a,b,c) f( A, a, b, c), P(:,1), P(:,2), P(:,3) );

BTW
It is best not to use i as a variable name in matlab.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.