[Top][All Lists]

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

Re: standalone application (octave to c++): define anonymous function fo

From: ola
Subject: Re: standalone application (octave to c++): define anonymous function for nonlin_curvefit()
Date: Mon, 11 Feb 2019 12:49:03 -0600 (CST)

I have one more question. 
What if my function does not have a simple form (@(p,x) 1-exp(-p(1)*x)), but
is calculated in the inner loop, as here:

Matrix my_fun(Matrix& p, Matrix& x, Matrix& y, Matrix& z) {
  octave_value_list out = octave::feval("zeros", ovl(y.rows(), x.cols()),
  Matrix k(out(0).matrix_value());
  for (unsigned int i = 0; i < x.cols(); ++i) {
    for (unsigned int ii = 0; ii < y.rows(); ++ii) {
      for (unsigned int iii = z(i,0); iii <= z(i,1); ++iii) {
       * k(ii, i) = k(ii, i) + (1-(exp( - p(iii-1) * x(0,i)))) *
  return k;       //here an error occure, when I call
octave::feval("lsqcurvefit", ovl(my_fun(p,x,y,z), ...);

Is it correct if I use this function in this way?
octave_value_list result = octave::feval("lsqcurvefit", ovl(my_fun(p,x,y,z),
init, xdata, ydata, L, U, opt(0)), 6);

Unfortunately, I've got an error, when I returned k: error: f(0,_):
subscripts must be either integers 1 to (2^63)-1 or logicals
so again, I don't know is it problem with my data or maybe I should do this
in other way?
Is there another function (similar to str2func) that allows my_fun to be
given as an argument to lsqcurvefit?

I hope you will help. Thank you.

Sent from:

reply via email to

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