From: Dhruv on
Hi,

I am trying to find the zeros of a function whose value I have at discrete points. Doing this in MATLAB directly is a matter of using a spline fit and subsquently using the fnzeros command to find all the roots of this data. So assuming that the function 'y' is specified at certain points 'x' I would do,

f1=spline(x,y);
f1roots=fnzeros(f1);

to find all the roots.

However, in my application this is a part of a large loop and to speed up things I am using the MEX interface in C language. I am wondering if someone knows how to use the spline function in a C MEX file?

As an example, I have been using the contour function of MATLAB within a C MEX file as follows,
mexCallMATLAB(1, &contmat, 2, continput, "contourc");
where the data is continput and the result of the contourc function is the array contmat.

In the case of spline however, the resulting answer is a structure and I am not sure how to interface MATLAB structures with those in C.
I would be very glad to receive help on any of these issues.
Thanks,
Dhruv
From: James Tursa on
"Dhruv " <dhruv.singh(a)gmail.com> wrote in message <ho1mkl$pj0$1(a)fred.mathworks.com>...
> Hi,
>
> I am trying to find the zeros of a function whose value I have at discrete points. Doing this in MATLAB directly is a matter of using a spline fit and subsquently using the fnzeros command to find all the roots of this data. So assuming that the function 'y' is specified at certain points 'x' I would do,
>
> f1=spline(x,y);
> f1roots=fnzeros(f1);
>
> to find all the roots.
>
> However, in my application this is a part of a large loop and to speed up things I am using the MEX interface in C language. I am wondering if someone knows how to use the spline function in a C MEX file?
>
> As an example, I have been using the contour function of MATLAB within a C MEX file as follows,
> mexCallMATLAB(1, &contmat, 2, continput, "contourc");
> where the data is continput and the result of the contourc function is the array contmat.
>
> In the case of spline however, the resulting answer is a structure and I am not sure how to interface MATLAB structures with those in C.
> I would be very glad to receive help on any of these issues.
> Thanks,
> Dhruv

For MATLAB mxArray structures, look at mxGetField and mxGetFieldByNumber in the MATLAB External Interfaces API. They have no relationship whatsoever to C structures.

James Tursa