help-octave
[Top][All Lists]
Advanced

[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: Mon, 18 Oct 2010 08:35:26 -0700 (PDT)

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 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?

Thanks again, have a nice evening,
   Alberto



Søren Hauberg wrote:
> 
> man, 18 10 2010 kl. 06:55 -0700, skrev AlbFrigerio:
>> Søren, you are completely right, but I'm not (yet) so crazy to create 100
>> variables instead of using a vector :) . I just proposed an example, I
>> just
>> needed to know ho to create sequential names.
> 
> If you need to store something more complicated than numbers in the
> variables, you should consider using a cell array. Something like
> 
>   b = cell (3, 1);
>   b {1} = "This corresponds to b_1";
>   b {2} = complex (3, 1);
>   b {3} = "And this corresponds to b_3";
> 
> and so forth.
> 
> I once (many years ago) had to maintain some software another guy wrote
> that used sequential variable naming and it was a major pain. For your
> own mental wellness I would really consider another solution than using
> b1, b2, ... :-)
> 
> Cheers
> Søren
> 
> _______________________________________________
> 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-tp3000216p3000466.html
Sent from the Octave - General mailing list archive at Nabble.com.



reply via email to

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