Custom component: Why do I have to "Configure for apps" repeatedly?
10 次查看(过去 30 天)
显示 更早的评论
I thought it would be a good idea to organize my app using a custom component to represent a recurring group of user interface objects. But here's the problem I'm finding: every time I restart Matlab, I can't load my main program unless I first load this custom component and go through the "Configure for apps" dialog. Saving the file doesn't help.
Is this for real? Or is there something I can do to make it stick?
0 个评论
回答(1 个)
Dinesh
2024-1-30
Hi Kenneth,
The reason that you are observing this behavior is because when you restart MATLAB, the path of the custom component is no longer on MATLAB path.
More info on MATLAB search path: https://www.mathworks.com/help/matlab/matlab_env/what-is-the-matlab-search-path.html
When you click on "Configure for apps" on the component, there is a also a dialog that allows you to click on the "Add to Path" button that adds this component to MATLAB path. Now, when you open your main program and try to load this component, MATLAB knows about this component since it's on its path. But when you close and open MATLAB again, I assume that the current folder you are in is the folder where the main program is written and not the folder where the custom component is present. Hence, MATLAB does not know about your custom component and you have to load it to MATLAB path to be able to load it in your main program.
The simplest fix is to have the main program and custom component in the same folder.
Even if you prefer to have the custom component in a different folder, you can use the "addpath" command in the MATLAB command window and specify the absolute path of the parent folder of the custom component as the argument to this function.
>> addpath('<Folder_path_of_custom_component>')
This adds the custom component to the MATLAB path and you will be abel to load it to your main program. You don't have to use the "Configure for apps" apps option in the custom component, since it it meant to do other things, not just adding the component to MATLAB path.
Documentation link for "addpath": https://www.mathworks.com/help/matlab/ref/addpath.html
Since you wouldn't want to do "addpath" every time you restart MATLAB, you can specify this "addpath" command in "startup.m" file. For more information on this, please refer to the following link:
I hope this helps!
2 个评论
Dinesh
2024-2-1
I tried reproducing your issue in R2023b, but couldn't. When the custom component and the main app where you are using this component are in the same folder, then it doesn't cause any issue in loading the main app even if MATLAB is restarted. Could you give more info on the main program and how you are loading the custom component? You may share the files as well.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Search Path 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!