arrayfun for function of multiple outputs of different sizes
Afficher commentaires plus anciens
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.
Réponses (1)
Honglei Chen
le 11 Juin 2012
rep = 10
x = randi(rep,1,rep)
[resultA,resultB] = arrayfun(@f,x,'UniformOutput',false)
Catégories
En savoir plus sur MATLAB dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!