[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Creating "sequential variable names"
From: |
AlbFrigerio |
Subject: |
Re: Creating "sequential variable names" |
Date: |
Tue, 19 Oct 2010 00:28:13 -0700 (PDT) |
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.
About the (possible) bug problem, I'll try in these days to understand what
went wrong, if I don't reach any solution I'll report it to the bug section.
Thanks again,
Alberto
John W. Eaton wrote:
>
> 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
>
> _______________________________________________
> Help-octave mailing list
> address@hidden
> https://www-old.cae.wisc.edu/mailman/listinfo/help-octave
>
>
--
View this message in context:
http://octave.1599824.n4.nabble.com/Creating-sequential-variable-names-tp3000216p3001576.html
Sent from the Octave - General mailing list archive at Nabble.com.
- Creating "sequential variable names", AlbFrigerio, 2010/10/18
- Re: Creating "sequential variable names", Andy Buckle, 2010/10/18
- Re: Creating "sequential variable names", Søren Hauberg, 2010/10/18
- Re: Creating "sequential variable names", AlbFrigerio, 2010/10/18
- Re: Creating "sequential variable names", Ben Abbott, 2010/10/18
- Re: Creating "sequential variable names", Søren Hauberg, 2010/10/18
- Re: Creating "sequential variable names", AlbFrigerio, 2010/10/18
- Re: Creating "sequential variable names", John W. Eaton, 2010/10/18
- Re: Creating "sequential variable names", Sergei Steshenko, 2010/10/18
- Re: Creating "sequential variable names", John W. Eaton, 2010/10/18
- Re: Creating "sequential variable names",
AlbFrigerio <=
- Re: Creating "sequential variable names", John W. Eaton, 2010/10/19
- Re: Creating "sequential variable names", AlbFrigerio, 2010/10/19
- Re: Creating "sequential variable names", Jaroslav Hajek, 2010/10/19