RETURN [message #86808] |
Wed, 04 December 2013 14:13  |
fd_luni
Messages: 66 Registered: January 2013
|
Member |
|
|
Hi
The following is a simple example of what I want to do:
a=[1,2,3]
b=[1,3,4]
return, a+b
But I got an error: Return statement in procedures can't have values.
Many Thanks
M
|
|
|
|
|
Re: RETURN [message #86816 is a reply to message #86810] |
Wed, 04 December 2013 18:21   |
Matthew Argall
Messages: 286 Registered: October 2011
|
Senior Member |
|
|
On Wednesday, December 4, 2013 6:33:03 PM UTC-5, fd_...@mail.com wrote:
> If I want to return more than one?
>
>
>
> I.e. a[1,2]
>
> b=[2,3]
>
>
>
> return, a+b, 2*a
>
>
>
> It says that the return statement in functions must have 1 value.
Functions in IDL are not like functions in, e.g., MatLab. You can only return one value. To do this, you must use a procedure and put the output variables in the calling statement.
pro foo, a, b, a_plus_b, twoa
a_plus_b = a + b
twoa = 2*a
end
;-----------------
a = [1,2]
b = [2,3]
foo, a, b, c, d
print, b, c
|
|
|
|
Re: RETURN [message #86818 is a reply to message #86817] |
Thu, 05 December 2013 01:55   |
Craig Markwardt
Messages: 1869 Registered: November 1996
|
Senior Member |
|
|
On Wednesday, December 4, 2013 9:33:37 PM UTC-5, wlandsman wrote:
> Another possibility is to return a 2 element vector
>
> return,[a+b, 2*a]
True, but A and B are listed as vectors already, so that may lead to some unintended consequences.
To Maria, IDL only lets you return one variable with the RETURN statement. To pass more data out of your function, you either need to concatenate arrays like Wayne showed, or use named variables like Matthew Argall showed. Neither is very intuitive for a non-programmer.
|
|
|
|