Undefined function or variable 'matscale'.

hello everyone, I have a question that my matlab code is packaged into Java code, when I try to test the packaging code(.jar)
error as: Undefined function or variable XXX(.mexw32 file ).
thank you very much

Answers (1)

The error message you are seeing suggests that the MEX file for the MATLAB function XXX is not included in the JAR file.
When packaging MATLAB code into a JAR file using the MATLAB Compiler, you need to ensure that all the required files, including MEX files, are included in the JAR file. This can be done using the mcc command line option -a to specify additional files that need to be included in the JAR file.
To include the MEX file for the XXX function in the JAR file, you can use the following command in MATLAB:
mcc -m yourMainFunction -a XXX.mexw32
Replace yourMainFunction with the name of your main MATLAB function that you want to package, and replace XXX.mexw32 with the name of the MEX file for the XXX function.
After running this command, you should see the MEX file included in the JAR file generated by the MATLAB Compiler. Make sure to use the updated JAR file in your Java application and try running it again.
If the issue persists, you can try adding any other required files or directories to the JAR file using the -a option as needed.

4 Comments

I added the file according to the method you said, and I see the MEX file included in the JAR file generated by the MATLAB Compiler. but the same problem still occurred.
Undefined function or variable 'matscale'.
It's always the same mistake. Is there any other way
If you're still getting the same error message after adding the MEX file to the JAR file generated by the MATLAB Compiler, it's possible that the MEX file is not being loaded correctly by MATLAB at runtime. Here are a few things you can try to fix the issue:
  1. Make sure that the MEX file is compatible with your operating system and MATLAB version. If the MEX file was compiled on a different operating system or MATLAB version than you're currently using, it may not work correctly.
  2. Check that the MEX file is being loaded correctly by MATLAB. You can use the mexext function to get the file extension of the MEX file for your system, and then use the loadlibrary function to load the MEX file into MATLAB. Here's an example code snippet:
mex_file = 'matscale.' + mexext; % replace 'matscale' with the name of your MEX file
loadlibrary(mex_file, 'matscale.h'); % replace 'matscale.h' with the name of your header file
  1. This code should load the MEX file into MATLAB and make the functions in the file available for use.
  2. Check that the MEX file is being called correctly by your Java code. Make sure that the classpath is set correctly to include the JAR file containing the MEX file, and that the Java code is calling the MEX function with the correct arguments.
If none of these steps solve the issue, you may need to provide more information about your setup and code to help diagnose the problem.
>>
there are some errors ,can you give me more advices
which mupadmex
D:\Program Files\MATLAB\R2015b\toolbox\symbolic\symbolic\mupadmex.mexw64
>> mcc -m pidtunner_main -a mupadmex.mexw64
Error using matlab.depfun.internal.MatlabInspector>resolveSymbolName (line 677)
File, function or class "mupadmex.mexw64" may not exist. Neither WHICH nor EXIST could find an exact, case-sensitive match. Please check the spelling of the name, and that any required directories are on the
MATLAB path.
Error in matlab.depfun.internal.MatlabInspector.resolveType (line 82)
[fullpath, symName] = resolveSymbolName(name);
Error in matlab.depfun.internal.MatlabInspector/determineType (line 155)
matlab.depfun.internal.MatlabInspector.resolveType( ...
Error in matlab.depfun.internal.Completion/resolveRootSet (line 1095)
determineType(inspector, name);
Error in matlab.depfun.internal.Completion/initializeRootSet (line 1347)
[rootSymbols, unknownType] = resolveRootSet(obj, files);
Error in matlab.depfun.internal.Completion (line 2171)
obj.RootSet = initializeRootSet(obj, files);
Error in matlab.depfun.internal.requirements (line 196)
c = matlab.depfun.internal.Completion(items, tgt, 'useDatabase');
Error using mcc
Unexpected error while determining required deployable files. Compilation terminated.
>> mex_file = mupadmex.mexw64 + mexext; % replace 'matscale' with the name of your MEX file
Undefined variable "mupadmex" or class "mupadmex.mexw64".
Nothing in the Symbolic Toolbox can be compiled.

Sign in to comment.

Asked:

on 30 Mar 2023

Commented:

on 3 Apr 2023

Community Treasure Hunt

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

Start Hunting!