Cannot load an object of class 'ClassificationKNN': Its class cannot be found in compiled executable

5 views (last 30 days)
Hi folks,
I try load load an object of ClassificationKNN from a mat file. Which works with no issues from the MATLAB Deskop.
If I compile the program using mcc -m program.m the above error occurs when I try to load the mat file:
Warning: Cannot load an object of class 'ClassificationKNN':
Its class cannot be found.
I tried the function pragma: '#function ClassificationKNN', now I get a different error:
The file
'C:\Program Files\MATLAB\R2019b\toolbox\stats\mlearnapp\+mlearnapp\+internal\+model\DatasetSpecification.m'
is not in the application's expanded CTF archive at
'C:\Users\...
This is typically caused by calls to ADDPATH in your startup.m or matlabrc.m files. Please see the compiler documentation and use the ISDEPLOYED function to ensure ADDPATH commands are not executed by deployed applications.
I should say, that I dont do anything with ADDPATH.
I also tried to create a dummy object:
Model = fitcknn(table(1,1), 1);
but i get the same error.
I tested this with 2019b and workaround for 2019b would be required.
Thanks
Michael

Answers (1)

Image Analyst
Image Analyst on 11 Apr 2022
It's probably caused by you not specifying the complete path of your .mat file.
See the FAQ:
Alternatively you can omit the folder of the mat file, when you call load() in your source code, if you include it with the -a option of mcc:
mcc -m program.m -a mymatfile.mat
  2 Comments
Michael Budach
Michael Budach on 12 Apr 2022
Edited: Michael Budach on 12 Apr 2022
When I write
disp("Loading a from " + pwd);
a = load("a.mat");
disp("Done Loading a");
and compile and run from the directory, where the source code was, I get:
Loading a from F:\path_to_source_code
Done Loading a
However, a is packed into the archive and it is loaded from there and not from the source path.
And when I specify the full path to load the knn model:
predictorModel = load("f:\path_to_source_code\PredictorModel.mat");
I get the samer error as I posted in the question:
The file
'C:\Program Files\MATLAB\R2019b\toolbox\stats\mlearnapp\+mlearnapp\+internal\+model\DatasetSpecification.m'
is not in the application's expanded CTF archive at
'C:\....'.
This is typically caused by calls to ADDPATH in your startup.m or matlabrc.m files. Please see the compiler documentation and use the ISDEPLOYED function to ensure ADDPATH commands are not executed by deployed applications.
Image Analyst
Image Analyst on 12 Apr 2022
You aren't trying to all an applet, like RegressionLearner, from your app are you? Because mini-programs like that are not allowed to be built into programs.
I'm not sure why loading a .mat file, which is basically just data, would cause it to try to run an m-file. Do you know what that DatasetSpecification.m file is or does?
Do you have any calls to cd or addpath in your source code?
You can call tech spport for help. I assume since you have the very expensive compiler toolbox you also have an active software maintenance agreement in place.

Sign in to comment.

Categories

Find more on Standalone Applications in Help Center and File Exchange

Products


Release

R2019b

Community Treasure Hunt

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

Start Hunting!