Hi everybody!
I need to assign values to a series of variables with numbered names,
such as
ks_1 = ... ;
ks_2 = ... ;
...
ks_N = ... ;
where N is big and is determined at runtime. I do not want to use a
vector named 'ks' such that ks(i) = ks_i and so on. Therefore, I used
the 'eval' function in this way:
for i=1:N
eval ( [ 'k', int2str(i), ' = ... ;' ] );
endfor
However, using 'eval' the execution time of my loop increases ~6 fold.
To test this behaviour, please try to run the following script:
tic();
for i=1:100000 sin(2); endfor
toc()
tic();
for i=1:100000 eval ( 'sin(2);' ); endfor
toc()
On my machine, the output is:
Elapsed time is 0.8 seconds.
Elapsed time is 5 seconds.
Could you please suggest a more performance-friendly workaround?
Actually, my numbered variables are fields of a structure (es.
struct.k_1, struct.k_2 ... ); I thought that one could solve the
problem by using pointers to access them, but I could not find support
for pointers in Octave.
Thank you,
Guido