Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

variable assignment - Create structures in loop and assign to another structure in IDL

In IDL I would like to create a structure in a loop with different data and then to assign them all to the main structure that will zip everything. I tried to used an array of structures, but I am stopped because I am not able to assign to the main structure:

alarm_list = { rg : 0, rf : 4}

alarm = { $  
          Alarm_Id : 0 , $  
          Range :      1, $
          Bin : 0        $ 
        }

arr = REPLICATE(alarm, 4)  
FOR ia = 0, 3 DO BEGIN
    alarm.alarm_id = ia
    alarm.bin = bin
    arr[ia] = alarm
    bin += 1
ENDFOR

I would like to assign all 4 alarms with different names (i.e. alarm1 = , alarm2 = ...) to the main "alarm_list". Thank you for your answers.

question from:https://stackoverflow.com/questions/65924262/create-structures-in-loop-and-assign-to-another-structure-in-idl

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You could try something along these lines, assigning to the array directly instead of using the alarm variable as an intermediate:

alarm_list= REPLICATE({alarm, Alarm_Id:0, Range:1, Bin:0},4)

FOR ia = 0, 3 DO BEGIN
    alarm_list[i].alarm_id = ia
    alarm_list[i].bin = bin
    bin += 1
ENDFOR

Hope this helps guide.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...