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: Mon, 18 Oct 2010 11:48:33 -0400

On 18-Oct-2010, AlbFrigerio wrote:

| 
| Dear Søren, I'll try in my awful English to explain why I decided to use
| sequential names. 
| 
| I got ten variables, I want to call AG1, ... , AG10.
| Every AG const of several elements : P,A,M,alpha, beta, gamma.
| Some of the previous elements const again of other elements : n, err,
| fitness, etc
| 
| As you suggested I tried to use struct : AG1 is a struct whose elements are
| P,M, etc. P is again a struct whose elements are n, err, etc. I believe
| there is a better way to implement it, but in this environment I don't want
| to type AG1.P.n = 1 ; AG2.P.n = 1, ... AG10.P.n =1 , AG1.M.err = 0, ...
| AG10.M.err = 0 , it is faster (and easier reading) what you suggested :
| 
| for i = 1 : 10
|     eval(sprintf("AG%d.P.n=1;AG%d.M.err=0",i,i));
| endfor

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.

If you find yourself using eval for what seem should be normal
programming tasks, then you should immediately think there must be a
better way, and nearly always there is.

| I hope you understood what is my need, as I told you I believe there is a
| nicer way to solve it, but I'm only a rookie in Octave :)
| 
| By the way, I got another question to you. Sometimes in the sprintf command
| I may use a reference to a function. Everything works fine, but if a put a
| keyboard command in the function (to start debug mode) my Octave crashes :
| it doesn't let me use the command line and after ctrl+C it crashes . Have
| you got any idea?

If you think you've found a bug in Octave, please submit a complete
bug report to the bug tracker here:

  https://savannah.gnu.org/bugs/?func=additem&group=octave

When reporting a bug, you need to provide everything necessary for
someone else to reproduce the problem.  Please read
http://www.octave.org/bugs.html for some tips about how to make a
useful bug report.

jwe



reply via email to

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