Re: name a variable with number [message #87458 is a reply to message #87449] |
Tue, 04 February 2014 06:41  |
Mats Löfdahl
Messages: 263 Registered: January 2012
|
Senior Member |
|
|
Den tisdagen den 4:e februari 2014 kl. 14:27:53 UTC+1 skrev sid:
> Hello sir,
>
> The main problem is, I will have a resultant array of
> n=dblarr(i,j)
> j=25,
> but i is varying say around 800 to 900.
> so i should name it in a for loop like,
>
> n1=n(800,1)
> n2=n(830,2)
> n3=n(840,3)
> .
> .
> .
> like this it has to go till 25.
I assume you mean n1=n(0:799,0), etc?
But why do you have to make each column in the 2D array into a separate variable? Isn't the data fine where it is?
> Finally I have to save this n1,n2,n3,....,n25 into separate files,
> like
>
> openw,2,'test.dat'
> printf,2,n1
> close,2
>
> till n25
This should work just as well with the original 2D array. Assume you have the lengths of the columns in an array lengths=[800,830,840,...], you could do something like:
for i=0,24 do begin
openw,2,'test'+strtrim(i,2)+'.dat'
printf,2,n[0:lengths[i]-1,i]
close,2
end
|
|
|