[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: indexing in octfile
From: |
David Bateman |
Subject: |
Re: indexing in octfile |
Date: |
Tue, 08 Feb 2005 18:27:28 +0100 |
User-agent: |
Mozilla Thunderbird 0.8 (X11/20040923) |
Brian Blais wrote:
David Bateman wrote:
Brian Blais wrote:
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
Thanks for the response,
I realize that this particular example is not a good use of the
octfile indexing, but it is simple enough that I can learn how to do
the more complicated example I am actually interested in.
Really, even in more complex cases, the example I showed is the better
way of going, as it removes all the nasty indexing issues from your
oct-file. You can also then use tricks like
double *result = m.fortran_vec();
for (int i = 0; i < nel; i++)
result[i] = ??;
and avoid all the expensive range checking, for maximum speed. If you
want a example then
DEFUN_DLD(myfun,args, , "")
{
NDArray m = args(0).array_value();
NDArray n = args(1).array_value();
octave_value_list ovl = idx_vector idx (Range (6, 8));
m.assign(ovl, n);
return m;
}
and the call "myfun(m,5)" or "myfun(m,6:8)" for example
Still I don't see the point...
D.
--
David Bateman address@hidden
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
-------------------------------------------------------------