- each time it is called, it closes all existing figures, even the one it created in a previous call,
- even if it didn't close existing figure, the figure number it uses is hard coded, so it would reuse the same figures,
- the function creates figures, sets callback on these figures and then returns. The callbacks are then called by matlab when the user interacts with the figures. So, most of the code is actually executed asynchronously, depending on when the user interacts on the figure. That's not appropriate for a loop.
How do I create a loop for a .m file that has multiple functions in it?
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Landon Ingle
il 19 Dic 2016
Commentato: Landon Ingle
il 19 Dic 2016
I have modified a .m file from https://www.mathworks.com/matlabcentral/fileexchange/25682-color-threshold (It takes an image and allows user to make some modifications to it).
Basically it is an .m file with multiple functions in it. I want to be able to run through multiple pictures contained in a specified folder. From my understanding I can't run a loop for all the functions, so I created a script as the following:
waitfor(msgbox('Choose the directory your pictures are in'))
directory=uigetdir; %Saves all files to this location
cd(directory)
i=1;
listFiles = dir('*.jpg');
for i=1:length(listFiles)
ColorThreshold(listFiles, i, directory)
end
However, it only loops through the first function of "ColorThreshold" (Cropping the image). It isn't until the last image that it actually runs through all the functions? I would like for it to go through all the functions contained in the .m file for every single picture. I am confused as why it only goes through all the functions in the .m file for the last image.
**Edit, it seems that it is running through all the functions in the .m file, but it is not waiting for any user input with the other functions. Is there a way for me to edit the functions so the loop only continues when I press a certain button?
Thanks for any help.
0 Commenti
Risposta accettata
Guillaume
il 19 Dic 2016
Note: local functions (functions below the main function in the main file) can only be called by the main function and are invisible to functions / scripts in other files. That's fine and is not your problem.
"It isn't until the last image that it actually runs through all the functions" No, your script never calls any of the local functions (because it can't) and it doesn't need to. There is actually nothing wrong with your script (except that it doesn't index listFiles in the loop), the problem is with the way the function is coded, it can't be called in a loop, because:
Più risposte (0)
Vedere anche
Categorie
Scopri di più su File Operations in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!