help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Creating "sequential variable names"


From: John W. Eaton
Subject: Re: Creating "sequential variable names"
Date: Tue, 19 Oct 2010 03:36:09 -0400

On 19-Oct-2010, AlbFrigerio wrote:

| Thanks a lot jwe, it looks very simple, as all the right things should be. I
| implemented it and everything works without using eval or something like
| that. 
| 
| > I think it is even clearer if you write
| > 
| >   for i = 1:10
| >     AG(i).P.n = 1;
| >     AG(i).M.err = 0;
| >   endfor
| > 
| > to create a struct array.

I should also mention that if you have a large number of elements in
your struct array, the above will be somewhat slow because AG will be
resized each time through the loop.  It will be faster to write
something like

  for i = 10:-1:1
    ..
  end

so that resizing happens only once.

jwe


reply via email to

[Prev in Thread] Current Thread [Next in Thread]