Re: Beginner: Oplot line t^(-5/3) [message #82028] |
Mon, 12 November 2012 12:25 |
Craig Markwardt
Messages: 1869 Registered: November 1996
|
Senior Member |
|
|
On Monday, November 12, 2012 11:20:31 AM UTC-5, Charlie Paul D'auria wrote:
> Hi there!
>
>
>
> Please bear in mind that I am a complete IDL beginner so excuse any foolishness!
>
>
>
> I have managed to plot an XY graph with data plots.
>
>
>
> My problem lies with my next stage: I need to generate a line of gradient t^(-5/3) (then use oplot over my data).
>
>
>
> I get the error 'Attempt to subscript T with I is out of range.' and when I type print,line I only get one value for my line...
>
>
>
> Here is some code I was provided with as a guide, which I have modified slightly:
>
>
>
> line=dblarr(9999)
>
> n=1E-4
>
> t=dblarr(9999)
>
>
>
> for i=0,9999 do begin
>
> t(i)=i
>
> line=n*t(i)^(-5./3.)
>
> endfor
>
The other posters showed you how to vectorize your problem. I'll point out the problem with your code.
A FOR loop from 0 through 9999 contains 10000 elements, because 0 is included in the count. Therefore you should dimension your variables with 10000 elements.
The IDL Way is that a variable declared like this,
T = dblarr(N)
Is stepped through like this,
FOR i = 0L, n_elements(T)-1 do begin ...
Note the "-1"
Craig
|
|
|
Re: Beginner: Oplot line t^(-5/3) [message #82032 is a reply to message #82028] |
Mon, 12 November 2012 08:37  |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
Charlie Paul D'auria writes:
> Please bear in mind that I am a complete IDL beginner so excuse any foolishness!
>
> I have managed to plot an XY graph with data plots.
>
> My problem lies with my next stage: I need to generate a line of gradient t^(-5/3) (then use oplot over my data).
>
> I get the error 'Attempt to subscript T with I is out of range.' and when I type print,line I only get one value for my line...
>
> Here is some code I was provided with as a guide, which I have modified slightly:
>
> line=dblarr(9999)
> n=1E-4
> t=dblarr(9999)
>
> for i=0,9999 do begin
> t(i)=i
> line=n*t(i)^(-5./3.)
> endfor
>
> I have used 9999 as 1E+5 was apparently too large, or something..
You need to find a better programming buddy. :-)
Try this, although I doubt this is what you really want:
line = (Dindgen(9999) + n)^(-5./3.)
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thue. ("Perhaps thou speakest truth.")
|
|
|
Re: Beginner: Oplot line t^(-5/3) [message #82033 is a reply to message #82032] |
Mon, 12 November 2012 08:35  |
Helder Marchetto
Messages: 520 Registered: November 2011
|
Senior Member |
|
|
On Monday, November 12, 2012 5:20:31 PM UTC+1, Charlie Paul D'auria wrote:
> Hi there!
>
>
>
> Please bear in mind that I am a complete IDL beginner so excuse any foolishness!
>
>
>
> I have managed to plot an XY graph with data plots.
>
>
>
> My problem lies with my next stage: I need to generate a line of gradient t^(-5/3) (then use oplot over my data).
>
>
>
> I get the error 'Attempt to subscript T with I is out of range.' and when I type print,line I only get one value for my line...
>
>
>
> Here is some code I was provided with as a guide, which I have modified slightly:
>
>
>
> line=dblarr(9999)
>
> n=1E-4
>
> t=dblarr(9999)
>
>
>
> for i=0,9999 do begin
>
> t(i)=i
>
> line=n*t(i)^(-5./3.)
>
> endfor
>
>
>
> I have used 9999 as 1E+5 was apparently too large, or something..
>
>
>
> Any help would be much appreciated!!
>
>
>
> Charlie
I would do it like this (using double precision):
n=1d-4
t=dindgen(9999)+1d ; starting from t=0 makes no sense, start from 1
line=n*t^(-5d /3d)
window, xsize=600, ysize=400 ; create a window for display
plot, t, line, /ylog ; plot in y-log coordinates
Avoid loops, unless strictly necessary.
Cheers,
Helder
|
|
|