arrayfun for function of multiple outputs of different sizes

Hi everyone,
This is my first message on this board. I'm wondering on how to avoid using loops in the following situation:
Let's say I have a simple function:
[A B] = f(x)
A = x;
B = linspace(0,x,11);
I'd like to run the following simple simulation without loops:
rep = 10; % number of simulations
seed = randi(rep,1,rep);
resultsA = zeros(rep,1);
resultsB = zeros(rep,11);
for i = 1:rep
[resultsA(i) resultsB(i,:)] = f(seed(i));
end
I've tried arrayfun but I keep getting error messages. My array cell knowledge is limited so please be explicit if you suggest a cell-related solution.
Thanks a lot.

Antworten (1)

Honglei Chen
Honglei Chen am 11 Jun. 2012
rep = 10
x = randi(rep,1,rep)
[resultA,resultB] = arrayfun(@f,x,'UniformOutput',false)

Kategorien

Mehr zu MATLAB finden Sie in Hilfe-Center und File Exchange

Gefragt:

am 11 Jun. 2012

Community Treasure Hunt

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

Start Hunting!

Translated by