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

1 view (last 30 days)
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.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 21 Feb 2012
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.

More Answers (0)

Categories

Find more on Structures in Help Center and File Exchange

Products


Release

R2011b

Community Treasure Hunt

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

Start Hunting!