Re: assign an array to an element in another array [message #90657 is a reply to message #90644] |
Fri, 20 March 2015 11:01  |
Russell[1]
Messages: 101 Registered: August 2011
|
Senior Member |
|
|
I third the suggestions. There are very few instances where you *actually* want to create a variable dynamically, everything else is where you're doing it wrong. Dick's suggestion of a hash is good if you have the modern versions of IDL (>8) and Matt's is good if you're ok with all the data being the same type. But my suggestion is to make an array of structures.
(1) prototype your data with a structure. Just making it up, I'd say it's like this:
foo={FOO,name:0,x:0,y:0,z:0,val:0d,nx:0,ny:0}
(2) then make this an array:
data=replicate({foo},n)
where n is the number of rows in your data set
(3) fill your dataset:
openr,lun,'myfile',/get_lun
for i=0,n-1 do begin
readf,lun,ind,x,y,z,val,nx,ny,f=format
data(i)={foo,ind,x,y,z,val,nx,ny}
endfor
free_lun,pun
you'll need to set the variable "FORMAT" in the readf line to be what you need, but that should be pretty easy.
Now you can access the data like...
plot,data.x,data.y,ps=6
or some such stuff.
-Russell
On Thursday, March 19, 2015 at 7:37:29 PM UTC-4, luc...@gmail.com wrote:
> Hello
> This is problem I have now,
> my data now looks like this
> 10 94 30 63 0.248019426 240 75
> 91 29 24 74 0.177277796 418 98
> 129 27 25 86 0.959739977 268 92
> 140 17 26 85 0.812485863 457 84
> 152 71 20 55 0.384820239 369 83
> 176 68 27 104 0.295040055 211 57
> 196 89 21 79 0.841609784 278 89
> 292 100 28 87 0.547060688 309 96
> 420 58 24 99 0.21125357 311 77
> 459 17 24 84 0.687962261 229 65
> 478 79 23 73 0.811294052 219 96
> 498 65 27 79 0.869434322 447 59
> 573 65 23 89 0.009937773 209 67
> 585 54 21 95 0.074036581 283 103
> 627 76 30 104 0.444237881 275 77
> 636 32 24 93 0.588080971 232 74
> 646 18 20 74 0.206121808 278 104
> 759 23 20 102 0.799160185 276 77
> 763 16 20 81 0.427796559 226 93
> 783 59 30 101 0.416701726 255 79
> 801 66 20 86 0.60898004 346 93
> 832 84 29 58 0.160208725 219 55
> 900 8 23 67 0.872238518 411 92
> 949 91 20 91 0.393444055 490 66
> 997 15 27 82 0.058078121 399 60
>
> I want to create 25 seprate vectors naming them with the forst element of each row... like this
>
> vec10= [94 30 63 0.248019426 240 75]
>
> vec91= [29 24 74 0.177277796 418 98]
>
> vec129= [27 25 86 0.959739977 268 92]
>
> vec140= [17 26 85 0.812485863 457 84]
>
> vec152= [71 20 55 0.384820239 369 83]
>
> vec176= [68 27 104 0.295040055 211 57]
>
> vec196= [89 21 79 0.841609784 278 89]
>
> vec292= [100 28 87 0.547060688 309 96]
>
> vec420= [58 24 99 0.21125357 311 77]
> ...
>
> how can I extract this values individually and then add the "VEC" portion to the name?
>
> I have tried "foreach" , I have try to convert them to strings and add them together, and nothing yet.
>
>
> Thank you
>
> -LM*M
|
|
|