Effacer les filtres
Effacer les filtres

How to returns to the current folder when i execut my gui?

4 vues (au cours des 30 derniers jours)
Abel Romero
Abel Romero le 19 Mai 2018
Commenté : Image Analyst le 19 Mai 2018
Hello everybody, I have a problem with my gui. All the figs and functions are saved in a defined directory. If I execute the GUI and then i change the current folder since the matlab editor the GUI does not works. Are there any solution to return to the current folder where my gui is saved?
I try to use cd, but when i run the GUI and i change the current folder, where it is saved, it does not work.

Réponses (1)

Image Analyst
Image Analyst le 19 Mai 2018
Simply keep track of the known folder, like in a field of handles, like handles.dataFolder. Then when you want to do anything with any files, put the base filename into full file and read it in:
fullFileName = fullfile(handles.dataFolder, 'whatever.dat');
You shouldn't need to know the folder where your program is. But if you really do, and you have Windows, see the attached function.
  2 commentaires
Abel Romero
Abel Romero le 19 Mai 2018
I think that i don't ask correctly the question. I will try to put an example:
All my figs and functions are saved in this path, for example: C:\Users\Abel\Documents\MATLAB\TFG_definitivo2\Project\Functions.
Then i execute the GUI, while it is executing i change the current folde in the comand window to: C:\Users\Abel\Documents\MATLAB\TFG_definitivo2\Project
Then i push a button in the GUI that is executing and it does not work and generates the following error: Undefined function or variable 'Welcome'.
Error in matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)Welcome('load_project_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating UIControl Callback.
So, the problem is that when i run the gui in the folder that i've saved it and i change the current folder it does not works.
Image Analyst
Image Analyst le 19 Mai 2018
So it has nothing to do with the folder and everything to do with some function or variable called Welcome not being defined. It's evidently in a different folder than your main program and you do not have a path set to it. You can add a path either with the Set Path tool on the tool ribbon, or in your OpeningFcn of your GUI code with this code:
folder = 'C:\Users\Abel\Documents\MATLAB\TFG_definitivo2';
% Add all functions in that folder and subfolders of it to the search path so it will find the functions.
addpath(genpath(folder));

Connectez-vous pour commenter.

Catégories

En savoir plus sur Environment and Settings dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by