For..Do loop. IDL Beginner [message #93792] |
Mon, 17 October 2016 16:46  |
smnadoum
Messages: 24 Registered: June 2016
|
Junior Member |
|
|
Hi,
I am trying to plot the following using For.. Do loop.
i. x, y2 ; psym = -4
ii. x, y3 ; psym = -5
iii. x, y4; psym = -6
Can anyone help? Thanks
|
|
|
Re: For..Do loop. IDL Beginner [message #93793 is a reply to message #93792] |
Tue, 18 October 2016 02:39   |
Nikola
Messages: 53 Registered: November 2009
|
Member |
|
|
On Tuesday, October 18, 2016 at 12:46:43 AM UTC+1, Cheryl wrote:
> Hi,
>
> I am trying to plot the following using For.. Do loop.
>
> i. x, y2 ; psym = -4
> ii. x, y3 ; psym = -5
> iii. x, y4; psym = -6
>
> Can anyone help? Thanks
From your question is not very clear what you want to do and why. I guess your problem is that y's are different functions with different number of elements so that you have to deal with different variable names in a loop.
Here is a quick solution that may help you to move forward. (Note that the EXECUTE command should be used with extra caution - read IDL help on it!.)
syms = [-4, -5, -6]
for i = 0, N_ELEMENTS(syms)-1 DO BEGIN
IF i eq 0 THEN cmd = 'plot' ELSE cmd = 'oplot'
log = EXECUTE(cmd + ', x, y'+strcompress(string(i), /rem)+', psym = syms[i]')
ENDFOR
|
|
|
Re: For..Do loop. IDL Beginner [message #93795 is a reply to message #93793] |
Tue, 18 October 2016 03:50   |
Markus Schmassmann
Messages: 129 Registered: April 2016
|
Senior Member |
|
|
On 10/18/2016 11:39 AM, Nikola Vitas wrote:
> On Tuesday, October 18, 2016 at 12:46:43 AM UTC+1, Cheryl wrote:
>> I am trying to plot the following using For.. Do loop.
>>
>> i. x, y2 ; psym = -4
>> ii. x, y3 ; psym = -5
>> iii. x, y4; psym = -6
> From your question is not very clear what you want to do and why. I
> guess your problem is that y's are different functions with different
> number of elements so that you have to deal with different variable
> names in a loop.
>
> Here is a quick solution that may help you to move forward. (Note
> that the EXECUTE command should be used with extra caution - read IDL
> help on it!.)
>
> syms = [-4, -5, -6]
> for i = 0, N_ELEMENTS(syms)-1 DO BEGIN
> IF i eq 0 THEN cmd = 'plot' ELSE cmd = 'oplot'
> log = EXECUTE(cmd + ', x, y'+strcompress(string(i), /rem)+', psym = syms[i]')
> ENDFOR
easiest is
g=plot(x, y2, psym = -4)
void=plot(x, y3, psym = -5, overplot=g)
void=plot(x, y4, psym = -6, overplot=g)
if it needs to be a loop, eighter use EXECUTE, or
p=ptrarr(3)
*p[0]=y2
*p[1]=y3
*p[2]=y4
g=!null
for i=0,2 do g=plot(x,*p[i],psym=-3-i,overplot=g)
You probably could use a LIST or another data type as well instead of
pointers, if you prefer.
|
|
|
|
Re: For..Do loop. IDL Beginner [message #93816 is a reply to message #93796] |
Thu, 27 October 2016 14:27   |
smnadoum
Messages: 24 Registered: June 2016
|
Junior Member |
|
|
On Tuesday, October 18, 2016 at 4:28:00 AM UTC-7, Haje Korth wrote:
> On Tuesday, October 18, 2016 at 5:39:23 AM UTC-4, Nikola Vitas wrote:
>> Here is a quick solution that may help you to move forward. (Note that the EXECUTE command should be used with extra caution - read IDL help on it!.)
>>
>
> I think you are missing the point. I seems that it is the OP's intent to avoid reading ANY IDL help or documentation and have the newsgroup solve all course exercises.
Hi Haje,
you are right, it is a course exercise for a course that I am actually not taking, this is basically an exercise that I am working on to learn IDL. I am only looking for help because I feel like I am stuck and don't know how to solve these IDL problems. I do have a couple of books that I am reading and when I don't find the answer I look online. You don't have to help if you don't want to. and instead of wasting 5 min of your time writing that comment, you couldve just ignored it if it bothers you this much.
please don't make any judgement from behind the monitor.
|
|
|
Re: For..Do loop. IDL Beginner [message #93963 is a reply to message #93816] |
Wed, 07 December 2016 12:23  |
Bill Davis
Messages: 4 Registered: June 1993
|
Junior Member |
|
|
On Thursday, October 27, 2016 at 5:28:01 PM UTC-4, Cheryl wrote:
> On Tuesday, October 18, 2016 at 4:28:00 AM UTC-7, Haje Korth wrote:
>> On Tuesday, October 18, 2016 at 5:39:23 AM UTC-4, Nikola Vitas wrote:
>>> Here is a quick solution that may help you to move forward. (Note that the EXECUTE command should be used with extra caution - read IDL help on it!.)
>>>
>>
>> I think you are missing the point. I seems that it is the OP's intent to avoid reading ANY IDL help or documentation and have the newsgroup solve all course exercises.
>
> Hi Haje,
>
> you are right, it is a course exercise for a course that I am actually not taking, this is basically an exercise that I am working on to learn IDL. I am only looking for help because I feel like I am stuck and don't know how to solve these IDL problems. I do have a couple of books that I am reading and when I don't find the answer I look online. You don't have to help if you don't want to. and instead of wasting 5 min of your time writing that comment, you couldve just ignored it if it bothers you this much.
> please don't make any judgement from behind the monitor.
; using direct graphics:
syms =[-4, -5, -6 ]
x = findgen(100)
y2 = x
y3 = x/3
y4 = x/4
y = [[y2], [y3], [y4]]
plot, x, y[*,0], psym=syms[0]
for i = 1, 2 do oplot, x, y[*,i], psym=syms[i]
|
|
|