Undefined function 'close' for input arguments of type 'char' when running app.

2 views (last 30 days)
I have a p-code Calc.p and a file Settings.m
The p-file executes the following steps:
  1. open window to select the folder with data files.
  2. load the data files.
  3. call the function Settings to set analysis paramters based on the data file name.
  4. perform data analysis.
  5. export results to datafiles and figures.
This p-code runs fine in my MATLAB environment without any error messages or warnings.
Next, I wrapped the p-code in the following, very simple, matlab code Embedded_P_code.m that just calls the p-code
% ==================
% Embedded .p code
Calc.p
% ==================
Next Embedded_p_code.m was compiled to an executable with the files Calc.p and Setting.m added to the folder 'Files required for your application to run'. No errors or warnings were shown during compilation.
Unfortunately, when running the Embedded_p_code.exe I get the following error message:
Undefined function 'close' for input arguments of type 'char'.
Question:
Why does this error pops up when running the executable and not when running the p-code in the Matlab environment?
My only wild guess is that the compiler can not analyze p-files for dependent files, i.e. dependent files have to be added manually to the folder 'Files required for your application to run'. However, apart from Setting.m, there are no other files required to run the p-file.
I know that the p-file uses the Signal Processing and Image Processing toolboxes which add-ons are both installed. I asume, I do not have to add these manually to the folder 'Files required for your application to run' during compilation.
Thanks for any comment, suggestion, answers or ideas.

Answers (2)

Walter Roberson
Walter Roberson on 17 Aug 2023

As an experiment it might be interesting to add something similar to

function varargout = close(varargin)
if ischar(varargin{1})
  this is the case being reported
  display appropriate information  
else
 [varargout{:}]  = builtin('close', varargin{:} );
end 

I certainly do not know, but I am wondering if somewhere the code is doing

close('all') 
  5 Comments
Walter Roberson
Walter Roberson on 21 Aug 2023
I think @Bas van der Vorst is the one doing the compiling?
If so then if they add the comment
%#function mat2gray
then mat2gray should get compiled into the executable.
Bas van der Vorst
Bas van der Vorst on 21 Aug 2023
Dear Walter, Just saw you comment now, but that's correct. I have added the produre I used to this thread. I started from the wrong foot with using the Application Compiler window which is easy to use at start but seems much less flexbile than the MATLAB mcc command.
Thank you all for your support!

Sign in to comment.


Bas van der Vorst
Bas van der Vorst on 21 Aug 2023
Edited: Bas van der Vorst on 21 Aug 2023
I resolved this case by
1) Using the following MATLAB code with to wrap the p-file:
Embedded_p_code.m
% ==================
% Embedded .p code
figure(1)
Calc.p
% ==================
2) No longer using the Application Compiler window but use MATLAB command line instead:
mcc('-m','Embedded_p_code','-a','Settings.m')
This resolves the original error that is related to closing a non-existent window (has to be solved in p-file by supplier).
3) Next, when running the Embedded_p_code.exe:
A command window is opened and in this case you see the error: " Unrecognized function or variable 'mat2gray' "
This is due to the fact that the p-file apparantly uses this function but since p-files cannot be analyzed for depencies,
this function, which is part of the Image Processing Toolbox has to be added manually.
4) Next, the function mat2gray is added to the list of files to be included during compilation:
mcc('-m','Embedded_p_code','-a','Settings.m','-a','mat2gray.m')
Note: Adding files manually to the compilation is much easier using the above command line than when using the MATLAB compiler window (if possible at all)
5) Finally, steps 3 and 4 are repeated until all dependencies are resolved (luckily only 4 files had to be added in my case ;) )
Conclusion:
Not a very nice process if you have to resolve a large number of dependencies but it worked for me and at least I can ask the supplier of the p-code to specifically supply this information next time.

Categories

Find more on Programming in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!