help-octave
[Top][All Lists]
Advanced

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

.oct - .m comparison


From: John W. Eaton
Subject: .oct - .m comparison
Date: Sat, 5 Feb 2011 10:46:56 -0500

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


reply via email to

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