help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: .oct - .m comparison


From: Fotios
Subject: Re: .oct - .m comparison
Date: Sat, 05 Feb 2011 16:55:27 +0100
User-agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; el; rv:1.9.2.13) Gecko/20101207 Thunderbird/3.1.7

Στις 2011-02-05 16:46, ο/η John W. Eaton έγραψε:
On  5-Feb-2011, Fotios wrote:

| In the process of learning the .oct interface i decided to write my
| previously .m function nestfunc (both attached +  a test file) in c++.
| There is no error check or anything and it seems that if your input is
| correct it returns correct answer. My problem is that when i make
| consequtive calls to nestfun without calling clear in between i get a
| segmentation violation (machine windows 7, octave 3.2.4 binary). It
| would be nice if someone could give me a hint about what is wrong.
|
| PS. The nestfunc.m file is relatively well documented if you need
| further details.

Compiling with

   mkoctfile -DBOUNDS_CHECKING=1 nestfun.cc

and then trying your example shows:

   octave:1>  nestfun (@(x)3.9*x.*(1-x), 0.1, 200);
   error: nestfun: A(I,J): row index out of bounds; value 2 out of bound 1

Stepping through your function with gdb should show you where this
problem occurs:

   gdb octave
   ...
   (gdb) r
   ...
   octave:1>  help nestfun  ## load nestfun.oct so gdb can find it
   ...
   octave:2>  ^C
   ...
   (gdb) b Fnestfun
   Breakpoint 1 at 0x7fffeb4ed5b0: file nestfun.cc, line 5.
   (gdb) c
   ...
   octave:2>  nestfun (@(x)3.9*x.*(1-x), 0.1, 200);
   ...
   (gdb) n
   (gdb)<RET>
   ... continue<RET>  until
   28       x(i, 0) = args(1).array_value (). elem(i);
   (gdb)
   error: nestfun: A(I,J): row index out of bounds; value 2 out of bound 1

I think you want your loop to be

   for (octave_idx_type i = 0; i<  rows; i++)

instead of

   for (octave_idx_type i = 0; i<= rows; i++)

jwe

Oops! indeed! It has been so long time since the last time i wrote sth starting my indexing at 0!. Thanks John.

/Fotis


reply via email to

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