Custom component: Why do I have to "Configure for apps" repeatedly?

13 Ansichten (letzte 30 Tage)
Kenneth
Kenneth am 29 Jan. 2024
Kommentiert: Dinesh am 1 Feb. 2024
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?

Antworten (1)

Dinesh
Dinesh am 30 Jan. 2024
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.
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.
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 Kommentare
Kenneth
Kenneth am 31 Jan. 2024
Bearbeitet: Kenneth am 31 Jan. 2024
No actually, the custom component IS in the selfsame directory as the main program. And this still keeps happening. I tried several custom components as I was getting the hang of Matlab, and I see the same behavior with every one. And everything is in the same directory.
Dinesh
Dinesh am 1 Feb. 2024
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.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Install Products finden Sie in Help Center und File Exchange

Produkte


Version

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by