Re: return two different values
- To: mathgroup at smc.vnet.net
- Subject: [mg83872] Re: return two different values
- From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
- Date: Mon, 3 Dec 2007 05:45:48 -0500 (EST)
- Organization: The Open University, Milton Keynes, UK
- References: <fitscg$4ft$1@smc.vnet.net>
vicky Al Aisa wrote:
> I am writing a module, from which i want to return 2 different values,
> one table and one just a normal int
>
> i used this syntax in module
>
> Return[EMean,MeanImg];
>
> and while receiving it in main program i use
>
> {MeanX,RedMeanVec}=CalcMean[RedImg];
>
>
> is this correct, because i am getting some error..which mean that the
> arguments are not matching.
> so i tried to define those arguments , like i defined RedmeanVec as a
> table, but still it doesn work
> Error is below
>
>
> Break::nofunc
> Continue::nofunc
> Return::nofunc
> function::nofunc: Function f not found enclosing expr.
>
> I use Mathematica 5.2
You must enclose the compound result within parentheses, i.e. you are
returning a _list_ of values. Note that you can safely discard *Return*
since Mathematica returns the value of the last statement evaluated.
In[1]:= f[data_] :=
Module[{a, b}, a = Mean[data]; b = Total[data]; {a, b}]
{x, y} = f[{{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}]
Out[2]= {{4, 5, 6}, {12, 15, 18}}
In[3]:= x
Out[3]= {4, 5, 6}
In[4]:= y
Out[4]= {12, 15, 18}
Regards,
--
Jean-Marc