prismofeverything
prismofeverything

Reputation: 9049

In matlab, how do I apply a function of two arguments to two cellarrays of equal length?

So I have two cell arrays:

A = {2 2 2 2}
B = {[1 2] [3 2] [5 5] [7 7]}

and a function of two arguments:

F = @(a, b) [a * b(1), (b(2) / 3), (b(1) + a) * 22]

And I want to apply the function to the two cell arrays like so:

idealfun(F, A, B)

and have it do the right thing (return a cell array with four cells of 1x3 vectors). Any ideas how to find/write idealfun?

Upvotes: 3

Views: 404

Answers (1)

Jonas
Jonas

Reputation: 74930

Use CELLFUN.

out = cellfun(F,A,B,'UniformOutput',false);

Upvotes: 5

Related Questions