close of gui resets current folder/path unintended
Mostrar comentarios más antiguos
Hey there, I have a bit of a problem, wich is not very urgent, but obstructive. I created a GUI with guide, wrote the respective code etc. everything's fine. But due to different progress I thought it might be wise to create another (but actually the same) GUI for further development. I know this isn't very "professional" but whatever. I created another folder directory containing all neccessary files, adjusted the code etc., everything works fine again, as a "different version". The structure would be like project/_version1_ or project/_version2_ where version1 is the old project and version2 the new (old) one. As it turns out, I need to be in project/_version2_ to start the new GUI, but after closing, matlab does reset the path to project/_version1_ which is pretty annoying (if you need to work within this directory) and driving me mad.
In case anybody has some additional Ideas HOW to find out, what causing this or even has an idea WHAT is causing this, I would love to here this. Obvious solutions like cd(...) have already been fixed and checkt without any success. Thanks in advance!
Respuestas (1)
Jan
el 20 de Ag. de 2017
after closing, matlab does reset the path to project/_version1_
Matlab does not change the current folder without being instructed to do so. You state, that you have fixed the cd() commands already, but obviously there is still one in the CloseRequestFcn or DeleteFcn. You can either look in the code or check the callbacks in GUIDE.
Without seeing the code, it is impossible to suggest a modification. If you cannot find the problem, creating a "trap-function" might help:
function cd(p)
disp(dbstack)
builtin('cd', p)
Create this function in a folder, which is inserted at the top of the path. Then each call of the cd() command shows the current calling stack. But if it is called from a callback, which is defined as a string, this stack will be empty.
The better and long term solution is not to change the current folder at all, but to use full path names when accessing files. This is required, if you work with different GUIs at the same time: If each GUI changes the current folder, the confusion will be perfect without the possibility to solve the problem. GUI and Timer callbacks could change the current folder freely. So better avoid cd() in general. Note that accessing files without an absolute path is fragile in Matlab also: E.g. fopen searches in the complete Matlab path for a file, which might not be intended.
Categorías
Más información sobre Search Path en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!