Path: news.mathworks.com!not-for-mail
From: "Sebastian " <seba.rivas@gmail.com>
Newsgroups: comp.soft-sys.matlab
Subject: How to assign function outputs to matrix elements?
Date: Thu, 20 Jun 2013 21:01:33 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 27
Message-ID: <kpvqjd$qn4$1@newscl01ah.mathworks.com>
Reply-To: "Sebastian " <seba.rivas@gmail.com>
NNTP-Posting-Host: www-04-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: newscl01ah.mathworks.com 1371762093 27364 172.30.248.35 (20 Jun 2013 21:01:33 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Thu, 20 Jun 2013 21:01:33 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 4315962
Xref: news.mathworks.com comp.soft-sys.matlab:797908

Hello everyone,

I've been trying to elegantly assign each of a function's multiple outputs to specific elements of an array, with no success. 

Example:

% Function:
[one two three] = myfun()
one = 1;
two = 2;
three = 3;
end

% Script
answers = zeros(3,1)
[answers(2,1) , answers(3,1) , answers(1,1)] = myfun();

This kind of script does not work, and I'm currently using auxiliary variables to make redundant assignments:
[a,b,c] = myfun();
answers(2,1) = a;
answers(3,1) = b:
answers(1,1) = c;


How can I fix this problem???

Thank you