Re: A smarter way to do this... [message #49592] |
Mon, 07 August 2006 15:41 |
JD Smith
Messages: 850 Registered: December 1999
|
Senior Member |
|
|
On Mon, 07 Aug 2006 15:32:09 -0700, ChiChiRuiz@gmail.com wrote:
> Hi all,
>
> I'm looking for a smarter way to solve the following problem... any
> help is appreciated..
>
> I have an array of structures with a specified size as follows : info =
> replicate({name, label:'', vector:floarr(1000)}, size)
>
> Each structure has 2 fields, the parameter and a vector: info[i] =
> {name, 'ParameterName', ParameterVector}. (Note: i cannot change this
> format)
>
> for example, info[0] = {name, 'paramA', vectorA}
> info[1] = {name, 'paramB', vectorB}
> ...
>
> My goal is make a vector with its own parameter name:
> paramA = vectorA
> paramB = vectorB
>
> but it can be tedious when the "size" is large...don't really want to
> list them for 100 times. Is there a smarter/easier way to loop this?
> or I'll have to list it by hand how ever many "size" times?
You should probably use pointers in a case like this, but you can do what
you suggest with:
for i=0,size-1 do (scope_varfetch(info[i].label))=info[i].vector
Now that you've saved yourself the tedium, what will you do with those 100
different variables? You'll probably want to loop over them again, in
which case they were better off left tucked in that structure.
JD
|
|
|