Deployed Matlab function with strage errors: functions not found

5 ビュー (過去 30 日間)
Christian D
Christian D 2024 年 9 月 27 日
コメント済み: Christian D 2024 年 9 月 30 日
Hi there,
I have a new company PC and had to install MATLAB on this PC. I'm currently facing some strange behaviour when deploying my functions and tools written with MATLAB.
I'm using ether MATLAB 2015aSP1 or 2015b as those two versions were the last providing 32bit support. The programs had to run also on older machine PCs therefore this restriction.
However when deploying even a simple function or small tool I always get some strange errors like the self written functions are not found (those functions are in a folder known to MATLAB). When running the functions or programs by MATLAB it works fine. The deployed version does not run.
I've installed the latest update for both MATLAB versions.
Im Using Windows 10 Enterprise (Version 10.019045). The MATLAB version is 8.5.1.959712 (R2015a) Service Pack 1 Update 3.
The first error is in which I run with startup.m
savepath('pathdef.m');
The error says "Error using savepath. Too many input arguments"
Canceling out this line I get errors on other lines. It seems that the depolyed version does not find the folder with all the user functions.
The make it more complicated: on my old company PC it worked fine.
Kind regards,
Christian

採用された回答

Image Analyst
Image Analyst 2024 年 9 月 29 日
Christian:
for some things to consider.
The deployed executable will run the startup.m code that was on the computer that compiled the code into a standalone executable. I'm pretty sure you should not use cd() or savepath() in your deployed code. There are a few reasons why but one of them is that the target computer may not have the same folder structure as your compiling computer. You can use isdeployed in your startup, or anywhere, to conditionally execute code on only target computers or compiling computers. Like
if ~isdeployed
% On development computer -- it's not deployed
newpath = whatever;
savepath(newpath)
else
% On target computer. Don't do anything.
end
Secondly I don't think you should be saving the current path to pathdef.m. It's just not necessary. Why would you want to? I compile and deploy standalone executables all the time and I've never done that. When would that file even ever get read?
In fact I think you should have gotten a compilation warning about using savepath() or cd(), though it's just a warning not a fatal error so it will still complete the compilation for you though the reason for the error may cause an actual error during runtime.
Paths are a tricky thing in deployed standalone executables. I've explained it many times before but basically the "current folder" is not where you think it is. It's not the folder where you placed your .EXE file on the target computer. See the FAQ: https://matlab.fandom.com/wiki/FAQ#Why_can't_my_standalone_compiled_executable_find_my_files?
I think the most likely solution is to explicitly specify the full path name of any file you want to use. The mcc compiler should find any dependent m-files your m-files call so that should not be a problem. However any other kinds of files, like data files, must be fully specified. Do not assume they will be found if you leave off the folder from the filename. Make sure you use fullfile to fully specify the complete path.
If that doesn't solve it, and I've only seen this twice so it's very rare, you can include the "missing" file by using the -a option in your mcc command.
You might also try calling my attached function, GetExecutableFolder, in your app's startup or initialization code (put in your app's m-file, not in your startup.m file).

その他の回答 (2 件)

Steven Lord
Steven Lord 2024 年 9 月 29 日
I am fairly certain that the limitation described in the "Do Not Rely on Changing Directory or Path to Control the Execution of MATLAB Files" section on this documentation page is not new and applied to release R2015a (and I think any version of MATLAB Compiler since version 4.0.) Also see the "Packaged Applications Do Not Process MATLAB Files at Run Time" section on that same page.
I think you're going to need to add the path that contains the helper functions to the MATLAB search path before you create the application. That way MATLAB Compiler can include them in the application when it is created.

Vandit
Vandit 2024 年 9 月 29 日
Hello Christian,
To resolve the error you're encountering, you can try restoring the default path and rehashing the toolbox cache. Please follow the steps below:
  • Before modifying the search path, it is important to take a backup of your 'pathdef.m' file, which can be located by using the command:
>> which -all pathdef
  • Ensure you make a safe copy of the file by moving it to a folder outside of your MATLAB path.
  • After taking the backup, execute the following commands in the MATLAB Command Window to restore the default MATLAB search path and rehash the toolbox cache.
>> restoredefaultpath
>> rehash toolboxcache
>> sl_refresh_customizations
  • After this step, kindly check if the issue occurs again. If the issue is resolved, then you may want to save the new MATLAB search path by executing the following command:
>> savepath
If the issue still persists, feel free to contact MathWorks Technical Support using the following link:
Hope this helps.
  1 件のコメント
Christian D
Christian D 2024 年 9 月 30 日
Thanks for the answer. I already found the answer in the error code: the isdeployed command was the answer as the writing is not allowed if the application is deployed.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeStartup and Shutdown についてさらに検索

製品


リリース

R2015a

Community Treasure Hunt

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

Start Hunting!

Translated by