Bypass uigetdir in function
Mostrar comentarios más antiguos
Hello everyone,
I am trying to run a script (i.e. script.m) inside my main script (i.e. main_script.m) and there is a uigetdir at the beginning of the script.m to select the folder in which it will work.
The problem is the following, I have to run script.m twice in my main_script.m and I do not want to choose the folder everytime. I also want to specify that I cannot change and/or modify any line in the script.m.
Here is an example of the main_script.m
% main_script.m
cd(dir1)
script % This is the script in which the uigetdir is
cd(dir2)
script % 2nd time but with a different directory
And an example for the script.m
% script.m
uigetdir
...
Is it possible to bypass the uigetdir function in a way that I do not have to click to select the folder ?
I noticed that if I use cd before starting the script, I just have to click "select folder" and it works. Is it possible, then, to automatically click on the "select folder" button without actually clicking ?
Thank you for your answers.
Sincerely
TM
4 comentarios
You are starting to discover the disadvantages of how beginners write code: repeatedly asking the user for input, cd to every directory, repeated code, uncontrollable scripts....
The best solution is to write better code, e.g.:
- write functions where any parameters are input arguments, then trivially define that folder once and pass it as an input argument to as many functions as you want.
- avoid slow and hard-to-debug cd by using efficient absolute/relative filenames.
Adam
el 18 de Mzo. de 2019
If you can't edit the code that does the thing you don't want then No, I can't think of a way to change its behaviour otherwise! You can play around with java.Robot to take control of mouse movements, but that is a vastly overblown solution.
Ideally you would simply edit the script, which should instead be a function rather than a script, too.
thibault
el 19 de Mzo. de 2019
Guillaume
el 19 de Mzo. de 2019
"it is shared between all these people and me. This is why I cannot really modifiy this code..."
For me that's all the more reasons to actually modify it and make it better for everyone. You can bet that you're not the only one who's having to work around that badly designed interface.
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Programming 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!