arrayfun for function of multiple outputs of different sizes
Mostrar comentarios más antiguos
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.
Respuestas (1)
Honglei Chen
el 11 de Jun. de 2012
rep = 10
x = randi(rep,1,rep)
[resultA,resultB] = arrayfun(@f,x,'UniformOutput',false)
Categorías
Más información sobre Creating and Concatenating Matrices en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!