From help-request at octave dot org Sun Feb 6 15:38:04 2005 Subject: de-for-ing.. From: Gorazd Brumen To: help at octave dot org Date: Sun, 06 Feb 2005 22:42:36 +0100 Hi again, Last time I received great suggestions from the list. Thanks again. I have another problem. I wonder if the following can be done nicer: x_init and x are two vectors. I want to get another vector - place - that is generated by for i = 1:lx place(i) = sum( x_init <= x(i) ); end I thought of doing it this way (with kronecker products - I am deeply into this right now, so it was the first thing that pops up) x_ext = kron (x, ones (n, 1)) x_init_ext = kron (ones (lx, 1), x_init ) x_tog = (x_init_ext <= x_ext) sum(reshape (x_tog,n,lx))' The results are the same, but the for loop is much faster and less memory consuming. the kron solution is preety much stupid. Is there a better way than the for loop? Regards, -- Gorazd Brumen Mail: brumen at isb dot unizh dot ch WWW: http://valjhun.fmf.uni-lj.si/~brumen PGP: Key at http://pgp.mit.edu, ID BCC93240 ------------------------------------------------------------- Octave is freely available under the terms of the GNU GPL. Octave's home on the web: http://www.octave.org How to fund new projects: http://www.octave.org/funding.html Subscription information: http://www.octave.org/archive.html -------------------------------------------------------------