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

7 次查看(过去 30 天)
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.

回答(2 个)

Walter Roberson
Walter Roberson 2023-8-17

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 个评论
Walter Roberson
Walter Roberson 2023-8-21
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 2023-8-21
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!

请先登录,再进行评论。


Bas van der Vorst
Bas van der Vorst 2023-8-21
编辑:Bas van der Vorst 2023-8-21
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.

类别

Help CenterFile Exchange 中查找有关 Programming 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by