Why does loading a MAT file that contains a function handle from a standalone C application return incorrect values?

I have a standalone application, written in C, that loads a MAT file using the R2011b MAT file API. This MAT file has a struct "mats" with three fields, "a", "b", and "c". For example:
mats.a=1;
mats.b=@(x)x^2;
mats.c=3;
When this MAT file is loaded into the standalone application, field "a" is obtained correctly, and field "b" returns a NULL pointer as expected, as function handles cannot be represented in standalone applications.
However, field "c" returns as a struct pointer rather than a double pointer as it should be. It seems that the fields loaded after the function handle field are incorrectly represented.

 채택된 답변

This is a bug in the MAT file API.
As a workaround, avoid loading MATLAB function handles into standalone applications.
If it is necessary to save a representation of a MATLAB function in such a MAT file, please use the FUNC2STR function to convert your function handles into strings, then store them in the MAT file, and then load them back into function handles when needed using the STR2FUNC function.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Write C Functions Callable from MATLAB (MEX Files)에 대해 자세히 알아보기

제품

릴리스

R2011b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by