help-octave
[Top][All Lists]
Advanced

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

Re: slow 'eval' function - maybe pointers would do?


From: Guido Walter Pettinari
Subject: Re: slow 'eval' function - maybe pointers would do?
Date: Fri, 6 Nov 2009 10:28:54 +0000

Dear Jaroslav,

I agree with you: I would never use my approach when the fields are more than, say, ~100. However, (i) I need only a few of S.ksi (ii) each of them is an array of numbers, not a scalar.

I often access, modify and plot structures' fields at Octave prompt. I just feel that addressing the variables with their name (e.g. S.k1) rather than with an index (e.g. S.k{1}) is quicker to type and less prone to errors. For example, the command:

plot ( S.k1, S.k2, '1x', S.k3, S.k4, '2x )

seems to me more easily typeable and readable than

plot ( S.k{1}, S.k{2}, '1x', S.k{3}, S.k{4}, '2x ).

Just a personal feeling :)

I would like to abuse of your kindness by asking two mailing-list questions:

1) When I reply to a mailing-list message, am I supposed to reply to the sender of the post as well? For example, should I include your personal email-address in the 'to' field? 2) Is it possible to attach text files or images when sending e-mails to the mailing list? Are there limits?

Thank you for your consideration.

Regards,

Guido

On Nov 6, 2009, at 9:51 , Jaroslav Hajek wrote:

On Thu, Nov 5, 2009 at 11:00 PM, Guido Walter Pettinari
<address@hidden> wrote:
Hello everybody!

Sorry for this late reply but I had much work to do in these days.

Thank you for all the answers. It was very instructive to learn all
the methods to handle with field names; I find particularly useful
what Benjamin pointed out, that is the possibility to create/access a
field via strings by using the parentheses:

for i = 1:N
field = sprintf ( 'something_%d', i );
S.(field) = whatever(i);
endfor

In this way the structures become really flexible!

@Carlo
but still I don't understand why you want to call your vectors
S.ks_ii,
I'm really curious: what's the problem with calling them KS{ii}?

I want to call the vectors in that way because I want a struct where
the fields are just column vectors. I like to access everything in the
structure S by just typing S.k1 or S.k2 rather than S.KS{i}. This is
just a personal preference, probably because I mainly program in C++
and I do not feel comfortable with cell arrays yet :)

Cheers,

Guido


While it probably won't matter until number get really big, you should
also realize that the syntax
S.ks{i} is not only more natural (requires no string manipulation
whatsoever), it is also more efficient.
When you give S a thousand fields ks1...ks1000, then s.ks200 requires
a binary search in 1000 strings, while
s.ks{i} doesn't. Your approach is asymptotically inferior.
In other words, the arguments for using cell arrays are the same as
for using arrays of numbers rather than name-mangled scalars.

regards

--
RNDr. Jaroslav Hajek
computing expert & GNU Octave developer
Aeronautical Research and Test Institute (VZLU)
Prague, Czech Republic
url: www.highegg.matfyz.cz



reply via email to

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