MCR executable different than original code

5 views (last 30 days)
Kurt on 15 Mar 2012
Answered: cem polat on 6 Aug 2015
I am using matlab to compile an .exe file, but when I run it I get error messages in several places that do not cause errors in the original code. For example, when I use the pdf function (from gmdistribution in the stats toolbox, which I included when compiling) I get:
Original code (gmq is definitely a distribution):
t=pdf(gmq,[xx(:,1) xx(:,2) xx(:,3)]);
Error message: {Error using pdf (line 54)
Requires the first input to be the name of a distribution.
Error in expectationsf_v1 (line 45)}
I've was able to get around this error somewhat. The problem (thanks Kaustubha!) was that the pdf function cannot tell that I am referring to the gmdistribution class when it's compiled, so I renamed the function gmpdf. That still didn't work though because there seems to be a problem with using objects in compiler. For example, when I run something like:
When I run this in matlab it works fine, but when I compile it and run the .exe I get the error message:
{Attempt to reference field of non-structure array.
Error in model13_main (line 243)
Does anyone have ideas about what the problem may be, or how to debug the code given that I can't replicate the error messages in matlab? I'm using 2011b and MCR version 7.16.
Arjun Viswanathan
Arjun Viswanathan on 4 Apr 2014
I had a similar error. The solution was to make sure all my classdef .m files were included in the "Files required for your application to run" box in applicationCompiler. That solved the issue for me.

Sign in to comment.

Answers (3)

Kaustubha Govind
Kaustubha Govind on 15 Mar 2012
It seems like the deployed version of the code is picking up the generic version of the pdf function which expects the first argument to be a string containing the name of a distribution, instead of gmdistribution.pdf. Somehow, the gmdistribution class is not getting compiled and included in the CTF correctly. I would recommend contacting MathWorks Tech Support if this is a bug that they have a resolution for.

owr on 16 Mar 2012
Whenever I run into errors like this using objects in a deployed appllication, I try the fix described here:
I havent looked at the details of your specific case much, but its an easy quick test.
Good luck.

cem polat
cem polat on 6 Aug 2015
I had the same problem with Matlab 2014b and java compiled MCR code. I used fitgmdist instead of and my problem was solved. Now that both MATLAB and java MCR class method works the same. fitgmdist is also offered by MATLAB help since will be removed in a future release.

Community Treasure Hunt

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

Start Hunting!

Translated by