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: Thu, 5 Nov 2009 22:00:22 +0000

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

P.S. Judd, I confere on you the prize for the most twisted solution :)))

On Oct 30, 2009, at 15:40 , Judd Storrs wrote:

for j=1:N
 eval(  [ 's.k', int2str(j), ' = ks ( :, j );' ]     );
endfor

If you want to make people shake their heads in disgust and pretend
they don't know you in public (probably also in private) while they
mutter under their breath about the coming of the end times and your
personal role as /the cause/ of hadal cooling, you can try (on linux
at least--I don't know how portable /dev/shm is to other unixen):

fid = fopen('/dev/shm/look_ma_no_eval.m','w') ;
fprintf(fid, "s.k%d = ks ( :, %d );\n" , 1:N, 1:N);
fclose(fid) ;
source /dev/shm/look_ma_no_eval.m ;
unlink /dev/shm/look_ma_no_eval.m ;

;)


--judd


P.S. Don't do this.

P.P.S. I have done this. /o\



reply via email to

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