Measurement Studio for VC++

cancel
Showing results for 
Search instead for 
Did you mean: 

How to define fitFunction of NonLinearFit in CNiMath class?

I defined a member function in my class:
double fitFunction (double x, double coef[ ], int size);
When I try to use it for CNiMath::NonLinearFit, I got an error "can not convert double(double, double[ ], int) to NI::CNiMath::NonLinearFit(_cdecl*)."
I don't know how to fix that, I also check the definition for FitModelFunction in CNiMath is:
typedef double FitModelFunction (double x, double coef[ ], int size);

Any answer will be appreciated and thank you very much for your help.

robin
0 Kudos
Message 1 of 3
(3,140 Views)
I created a quick Measurement Studio test project and added the following function in my dialog source file:

static double FitModelFunction(double x, double coef[], int size)
{
return 0.0;
}

I then called CNiMath::NonLinearFit like this:

CNiReal64Vector x, y, z, coef;
double mse;

// ...

CNiMath::NonLinearFit(x, y, FitModelFunction, z, coef, mse, -1);

This built OK for me. Is this different than what you were doing? If this doesn't help, could you please post some sample code that demonstrates how you're declaring the callback function and specifying it to NonLinearFit? Thanks.

- Elton
Message 2 of 3
(3,140 Views)
Thank you very much.
The way is correct. That frees the syntax of pointer "double (myclass :: FitModelFunction )(double x, double coef[], int size)", now the pointer is" double (FitModelFunction )(double x, double coef[], int size)".

robin
0 Kudos
Message 3 of 3
(3,140 Views)