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

Home » Public Forums » archive » RETURNING VALUES FROM FUNCTIONS
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
RETURNING VALUES FROM FUNCTIONS [message #91408] Fri, 10 July 2015 07:14 Go to next message
Priyadarsini Sivaraj is currently offline  Priyadarsini Sivaraj
Messages: 15
Registered: June 2015
Junior Member
Hello everyone,

I would like to know if there is any way to return two values from a function.

I have reached a point where its necessary for me to return TWO matrices from a single function. Is there any way that I can do it..?
Re: RETURNING VALUES FROM FUNCTIONS [message #91409 is a reply to message #91408] Fri, 10 July 2015 07:49 Go to previous messageGo to next message
Helder Marchetto is currently offline  Helder Marchetto
Messages: 520
Registered: November 2011
Senior Member
On Friday, July 10, 2015 at 4:14:23 PM UTC+2, Priyadarsini Sivaraj wrote:
> Hello everyone,
>
> I would like to know if there is any way to return two values from a function.
>
> I have reached a point where its necessary for me to return TWO matrices from a single function. Is there any way that I can do it..?

I know of at least 2 ways of doing that:
1. use parameters:

function doubleXY, x, y
x = x*2
y = y*2
return, x
end

If you run this this way:
x = 3
y = 5
print, doubleXY(x,y)
print, x
print, y

you will find that:
- it prints 6, 6, 10. Now x and y have new values: 6 and 10.

2) the other way is to return a structure:
function doubleXY, x, y
return, {x:x*2,y:y*2}
end

This will return:
{
"X": 6,
"Y": 10
}


That solves your problem, but please next time:

- have a look at the IDL help. It might seem strange, but sometimes you find the answers on your own. This will be a win-win for you. You will solve the problem and *understand" why it is solved.

- give us an example to show your commitment. You've tried "this and that" and could not get "that other thing". It shows us exactly where you're stuck and tells us that you've been trying before asking for help.

- if none of the above work out, then google your problem. I tried that and guess what: I found a better answer than mine:
google "idl return two values from a function"
and this is the first hit for me:
https://www.physics.wisc.edu/~craigm/idl/archive/msg02654.ht ml
that actually comes from here:
https://groups.google.com/forum/#!searchin/comp.lang.idl-pvw ave/Multiple$20values$20from$20a$20function/comp.lang.idl-pv wave/94c1udxeE1c/nCwx7WaJ7gMJ

Good luck next time.
Helder
Re: RETURNING VALUES FROM FUNCTIONS [message #91410 is a reply to message #91408] Fri, 10 July 2015 08:13 Go to previous message
Priyadarsini Sivaraj is currently offline  Priyadarsini Sivaraj
Messages: 15
Registered: June 2015
Junior Member
On Friday, 10 July 2015 10:14:23 UTC-4, Priyadarsini Sivaraj wrote:
> Hello everyone,
>
> I would like to know if there is any way to return two values from a function.
>
> I have reached a point where its necessary for me to return TWO matrices from a single function. Is there any way that I can do it..?

Yeah sure..Thanks a lot..:-)
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Leap Seconds and JULDAY()
Next Topic: Extracting data over land surface and exclude data over ocean in IDL

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

Current Time: Wed Oct 08 15:37:08 PDT 2025

Total time taken to generate the page: 0.00686 seconds