Hey guys, I'm a beginner here in Idl and at the moment, I have to create a program and I'm trying to organize the vectors by the index. I mean, the way I was doing it before, I was overlapping the values, so I want to change it. Here is the problem: The program is about astrophysics and I got describe the behavior of some stars using monte carlo simulation. Here is the way I Declare my vector. The first collumn reffers to time, and the other one is the number of stars. VarM2=fltarr((nt+nt2),E02) VarM3=fltarr((nt+nt2),E03) VarM4=fltarr((nt+nt2),E04) VarM5=fltarr((nt+nt2),E05) VarM8=fltarr((nt+nt2),E08) VarM10=fltarr((nt+nt2),E10) But now I want them to look like following a sequence, instead going from 0 to E02 ( A number of stars), goes form 0 to X (All number of stars) so I tried this : For B=0,((nt+nt2)-1)do begin For I=0,E02-1 do VarM2[B,I]=[B,0] For I=E02,(E02+E03-1)do VarM3[B,I]=[B,0] For I=E02+E03,(E02+E03+E04-1) do VarM4[B,I]=[B,0] For I=E02+E03+E04,(E02+E03+E04+E05-1)do VarM5[B,I]=[B,0] For I=E02+E03+E04+E05,(E02+E03+E04+E05+E08-1) do VarM8[B,I]=[B,0] For I=E02+E03+E04+E05+E08,(E02+E03+E04+E05+E08+E10-1) do VarM10[B,I]=[B,0] Endfor The idea here is like: Let's say E02 is 5, and E03 is 10, then VarM2 goes from 0 to 5, then VarM3 goes from 5 to 10 And then I got the error: Attempt to subscript VARM3 with I is out of range. Then I tried another way, kind of resuming everything in one vector I declare this vetor with the size NP (Np here means the total number of stars) and (nt+nt2) reffers to time, just like above VarM=fltarr((nt+nt2),Np) VarM=[VarM2,VarM3,VarM4,VarM5,VarM8,VarM10] Then Idl says : Unable to concatenate variables because the dimensions do not agree: VARM3. Does anyone know how to solve this? I would be glad if someone could help me!

0 |

11/23/2016 9:35:27 PM

On Wednesday, November 23, 2016 at 10:35:30 PM UTC+1, Edson Filho wrote: > Hey guys, I'm a beginner here in Idl and at the moment, I have to create a program and I'm trying to organize the vectors by the index. I mean, the way I was doing it before, I was overlapping the values, so I want to change it. Here is the problem: > > The program is about astrophysics and I got describe the behavior of some stars using monte carlo simulation. Here is the way I Declare my vector. The first collumn reffers to time, and the other one is the number of stars. > > VarM2=fltarr((nt+nt2),E02) > VarM3=fltarr((nt+nt2),E03) > VarM4=fltarr((nt+nt2),E04) > VarM5=fltarr((nt+nt2),E05) > VarM8=fltarr((nt+nt2),E08) > VarM10=fltarr((nt+nt2),E10) > > But now I want them to look like following a sequence, instead going from 0 to E02 ( A number of stars), goes form 0 to X (All number of stars) so I tried this : > > For B=0,((nt+nt2)-1)do begin > For I=0,E02-1 do VarM2[B,I]=[B,0] > For I=E02,(E02+E03-1)do VarM3[B,I]=[B,0] > For I=E02+E03,(E02+E03+E04-1) do VarM4[B,I]=[B,0] > For I=E02+E03+E04,(E02+E03+E04+E05-1)do VarM5[B,I]=[B,0] > For I=E02+E03+E04+E05,(E02+E03+E04+E05+E08-1) do VarM8[B,I]=[B,0] > For I=E02+E03+E04+E05+E08,(E02+E03+E04+E05+E08+E10-1) do VarM10[B,I]=[B,0] > Endfor > > The idea here is like: > Let's say E02 is 5, and E03 is 10, then VarM2 goes from 0 to 5, then VarM3 goes from 5 to 10 > > > And then I got the error: > > Attempt to subscript VARM3 with I is out of range. > > Then I tried another way, kind of resuming everything in one vector > > I declare this vetor with the size NP (Np here means the total number of stars) and (nt+nt2) reffers to time, just like above > VarM=fltarr((nt+nt2),Np) > VarM=[VarM2,VarM3,VarM4,VarM5,VarM8,VarM10] > > Then Idl says : > Unable to concatenate variables because the dimensions do not agree: VARM3. > > > Does anyone know how to solve this? I would be glad if someone could help me! Hi, I think your second solution was pretty close: > VarM=fltarr((nt+nt2),Np) > VarM=[VarM2,VarM3,VarM4,VarM5,VarM8,VarM10] Try this instead: ; this you can skip -> VarM=fltarr((nt+nt2),Np) VarM=[[VarM2],[VarM3],[VarM4],[VarM5],[VarM8],[VarM10]] It works for me: IDL> nt = 2 IDL> nt2 = 3 IDL> e02 = 4 IDL> e03 = 5 IDL> e04 = 6 IDL> totalStars = e02+e03+e04 IDL> VarM2=fltarr((nt+nt2),E02) IDL> VarM3=fltarr((nt+nt2),E03) IDL> VarM4=fltarr((nt+nt2),E04) IDL> print, 'total stars ', totalStars IDL> print, 'total time ', nt+nt2 IDL> varM = [[VarM2],[VarM3],[VarM4]] IDL> help, varM total stars 15 total time 5 VARM FLOAT = Array[5, 15] cheers, Helder

0 |

11/24/2016 7:51:52 AM

It worked! Thank you so much Helder! It really helped me a lot. Didn't even though to look into the brackets.

0 |

11/25/2016 5:12:30 PM