Re: Add a new tag for anonymous structure array [message #58861] |
Thu, 21 February 2008 22:03 |
geonline714
Messages: 7 Registered: April 2007
|
Junior Member |
|
|
Wayne,
Thank you so much!!! I was using loop to solve the problem, but your
method is much better!
Sincerely,
Qi
On Feb 21, 5:24 pm, wlandsman <wlands...@gmail.com> wrote:
> On Feb 21, 7:20 pm, geonline...@gmail.com wrote:
>
>> I have an anonymous structure array, say, A.Let us assume the size of
>> the array is 100. Each structure has tags A, B,C. I want to add a new
>> tag, D. How to do that in IDL?
>> I tried:
>> myStruct = create_struct(A, 'D',0), but it failed.
>
>> It seems that the above syntax works only for an individual structure
>> instead of structure array.
>> For example,
>
>> myStruct = create_struct(A[0],'D',0) and it works.
>
>> This is an issue that can be easily solved in matlab. I am not sure
>> whether IDL provides straightforward method to do that.
>
> I wouldn't call this straightforward but the task can be accomplished
> by
>
> myStruct = replicate( create_struct(A[0],'D',0),
> N_elements(A) ) ;Create the new structure
> Struct_Assign, a, myStruct ;Fill with values from the original
> structure
>
> --Wayne
|
|
|
Re: Add a new tag for anonymous structure array [message #58862 is a reply to message #58861] |
Thu, 21 February 2008 19:24  |
wlandsman
Messages: 743 Registered: June 2000
|
Senior Member |
|
|
On Feb 21, 7:20 pm, geonline...@gmail.com wrote:
> I have an anonymous structure array, say, A.Let us assume the size of
> the array is 100. Each structure has tags A, B,C. I want to add a new
> tag, D. How to do that in IDL?
> I tried:
> myStruct = create_struct(A, 'D',0), but it failed.
>
> It seems that the above syntax works only for an individual structure
> instead of structure array.
> For example,
>
> myStruct = create_struct(A[0],'D',0) and it works.
>
> This is an issue that can be easily solved in matlab. I am not sure
> whether IDL provides straightforward method to do that.
I wouldn't call this straightforward but the task can be accomplished
by
myStruct = replicate( create_struct(A[0],'D',0),
N_elements(A) ) ;Create the new structure
Struct_Assign, a, myStruct ;Fill with values from the original
structure
--Wayne
|
|
|