Path: news.mathworks.com!newsfeed-00.mathworks.com!news.kjsl.com!feeder.erje.net!eu.feeder.erje.net!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!feeder1.enfer-du-nord.net!gegeweb.org!aioe.org!.POSTED!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: How to assign function outputs to matrix elements?
Date: Thu, 20 Jun 2013 16:13:37 -0500
Organization: Aioe.org NNTP Server
Lines: 70
Message-ID: <kpvr9u$ci6$1@speranza.aioe.org>
References: <kpvqjd$qn4$1@newscl01ah.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: 4yOShoc9HsNcKBt23n+aUQ.user.speranza.aioe.org
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Complaints-To: abuse@aioe.org
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/20130509 Thunderbird/17.0.6
X-Notice: Filtered by postfilter v. 0.8.2
Xref: news.mathworks.com comp.soft-sys.matlab:797910

On 6/20/2013 4:01 PM, Sebastian wrote:
> 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
>


Replace the line

        [one two three] = myfun()

with

       function [one two three] = myfun()

You need the word 'function' in there.

-------------------------
function foo( )

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

answers
end

function [one two three] = myfun()
one = 1;
two = 2;
three = 3;
end
-----------------------------

EDU>> foo

answers =

      3
      1
      2



--Nasser