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

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.

Respuestas (2)

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 comentarios

Well, it's doubly tough to conjecture when can't see the code to even see where a line calling close is...obviously it would be helpful if OP would post the m-file, but I suppose he turned into p-file because thinks it's sensitive.
I wonder if by any chance a compiled app would generate an error that doesn't at command line if called close() on an non-existent figure or with the 'all' argument with none open...
But without anything at all to look at, don't see much hope in anybody here being able to help...
1) I agree that it is hard to debug this without having the original .m code but since this is considered propriety knowledge it will not be released to me.
But in spite of this, your comments are helpfull, since the error is very likely generated by the fact that p-file calls 'close' or close("all") on an non existent figure.
This I checked by wrapping the p-code in a .m code that first opens a (dummy) figure and next calls the p-code
% ==================
% Embedded .p code
figure(1)
Calc.p
% ==================
In this way, there is an existing figure that can be closed by the app.
After compiling this code, the executable runs fine up to the point where I can select the folder with data to be analyzed. With this I can go back to the supplier of the p-file to correct that in his .m MATLAB code.
2) Unfortunately, after solving the above, I ran into another, similar issue:
Now the exectable app comes back with the error message:
Undefined function 'mat2gray' for input arguments of type 'double'
Here 'mat2gray' is part of the Image Processing Toolbox to which I do have license, i.e. it has the status 'installed' when checking at 'Manage Add-Ons'.
Notes:
  • I upgraded matlab to thew latest version 2023a to avoid version issues
  • It remains strange that no errors occur when running the p-file in the MATLAB environment.
But maybe I should open a new thread for this one.
If you're not the one compiling the app, then the setup isn't the same between systems and sounds as though the supplier didn't do a good job of ensuring the differences between running in the MATLAB environment and in a compiled app are handled correctly and that his code isn't dependent upon his particular setup.
Again, will be nearly impossible for anybody here to be able to do much of anything with it as a black hold object.
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.
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!

Iniciar sesión para comentar.

Bas van der Vorst
Bas van der Vorst el 21 de Ag. de 2023
Editada: Bas van der Vorst el 21 de Ag. de 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.

Categorías

Más información sobre Programming en Centro de ayuda y File Exchange.

Preguntada:

el 17 de Ag. de 2023

Comentada:

el 21 de Ag. de 2023

Community Treasure Hunt

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

Start Hunting!

Translated by