comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » RETURN
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
RETURN [message #86808] Wed, 04 December 2013 14:13 Go to next message
fd_luni is currently offline  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 #86809 is a reply to message #86808] Wed, 04 December 2013 14:19 Go to previous messageGo to next message
Burch is currently offline  Burch
Messages: 28
Registered: December 2013
Junior Member
On Wednesday, December 4, 2013 4:13:15 PM UTC-6, fd_...@mail.com wrote:
> 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

You should write a function instead of a procedure.

http://www.exelisvis.com/docs/Defining_a_Function.html

-Jeff
Re: RETURN [message #86810 is a reply to message #86809] Wed, 04 December 2013 15:33 Go to previous messageGo to next message
fd_luni is currently offline  fd_luni
Messages: 66
Registered: January 2013
Member
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.
Re: RETURN [message #86816 is a reply to message #86810] Wed, 04 December 2013 18:21 Go to previous messageGo to next message
Matthew Argall is currently offline  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 #86817 is a reply to message #86810] Wed, 04 December 2013 18:33 Go to previous messageGo to next message
wlandsman is currently offline  wlandsman
Messages: 743
Registered: June 2000
Senior Member
On Wednesday, December 4, 2013 6:33:03 PM UTC-5, fd_...@mail.com wrote:

>
> return, a+b, 2*a
> It says that the return statement in functions must have 1 value.

Another possibility is to return a 2 element vector

return,[a+b, 2*a]
Re: RETURN [message #86818 is a reply to message #86817] Thu, 05 December 2013 01:55 Go to previous messageGo to next message
Craig Markwardt is currently offline  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.
Re: RETURN [message #86820 is a reply to message #86818] Thu, 05 December 2013 03:34 Go to previous message
Phillip Bitzer is currently offline  Phillip Bitzer
Messages: 223
Registered: June 2006
Senior Member
Or, you can return a structure:

str = {sum:a+b, multiply:2*a}

RETURN, str

END
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: plotting missing values
Next Topic: PS fonts

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 13:47:46 PDT 2025

Total time taken to generate the page: 0.00440 seconds