arrayfun for function of multiple outputs of different sizes
Show older comments
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.
Answers (1)
Honglei Chen
on 11 Jun 2012
rep = 10
x = randi(rep,1,rep)
[resultA,resultB] = arrayfun(@f,x,'UniformOutput',false)
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!