From help-request at octave dot org Tue Feb 8 09:38:10 2005 Subject: Re: indexing in octfile From: David Bateman To: Brian Blais Cc: help at octave dot org Date: Tue, 08 Feb 2005 16:40:07 +0100 Brian Blais wrote: > Hello, > > I have a question about doing indexing in an oct file. > > If the following cc code: > > Matrix m = args(0).matrix_value(); > idx_vector idx(Range (3,6)); > Matrix ret = (Matrix) m.index (idx, 0); > > is equivalent to the following octave code: > > ret=m(3:6); > > what is the equivalent cc code for: > > m(3:6)=5 > > or > > m(3:6)=6:8; > > or > > m(3:6)=m(3:6)+6:8; The equivalent to index is "assign" which you'll find in ov-base-mat.cc. However, I don't see a case where you should use such an example. Better to write a generic function and do the indexing/assignment exterior to the function eg DEFUN_DLD(myfun, args, , " ") { NDArray m = args(0).array_value(); double d = args(1).double_value(); int nel = m.numel(); for (int i = 0; i < nel; i++) m(i) += d + i; return m; } and then do m(3:6) = myfun(m(3:6),6); This is much cleaner D. -- David Bateman David dot Bateman at motorola dot com Motorola Labs - Paris +33 1 69 35 48 04 (Ph) Parc Les Algorithmes, Commune de St Aubin +33 1 69 35 77 01 (Fax) 91193 Gif-Sur-Yvette FRANCE The information contained in this communication has been classified as: [x] General Business Information [ ] Motorola Internal Use Only [ ] Motorola Confidential Proprietary ------------------------------------------------------------- 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 -------------------------------------------------------------