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.

답변 (1개)

Honglei Chen
Honglei Chen 2012년 6월 11일
rep = 10
x = randi(rep,1,rep)
[resultA,resultB] = arrayfun(@f,x,'UniformOutput',false)

카테고리

도움말 센터File Exchange에서 MATLAB에 대해 자세히 알아보기

질문:

2012년 6월 11일

Community Treasure Hunt

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

Start Hunting!

Translated by