- if the user cancels or closes the dialog box then the indexing info.name{i}(1:5); will throw an error.
- The code if info.vnr{i} == 0 will only be considered true (and thus the code within the IF executed) if the first five characters of the filename are null characters, which is very very unlikely in any filename.
Why does uigetfile not ask for another input in a for loop
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Jan Sailer
el 10 de Abr. de 2025
Respondida: Jan Sailer
el 10 de Abr. de 2025
I have a small for loop in which I try to load several input files and store them as well as some meta data in various variables. The first iteration runs fine, but on the second loop iteration the code skips over the uigetfile command and instead of letting me select another file, it just fills the next entry in my cell aray with [0].
I am using Matlab 2024b at the moment but the script was originally written in Matlab 2022b, where it was (and still is) working perfectly fine. The loop is incredibly simple:
for i = 1:4
[info.name{i}, info.path{i}] = uigetfile('', ['File Nr. ', num2str(i), ' auswaehlen.']);
info.vnr{i} = info.name{i}(1:5);
if info.vnr{i} == 0
error('Kein valides Inputfile ausgewählt')
end
end
Has the syntax for uigetfile changed? I have recently added the new Desktop App that allows me to use dark mode, but that shouldn't change how code works, right?
2 comentarios
Stephen23
el 10 de Abr. de 2025
Editada: Stephen23
el 10 de Abr. de 2025
It worked for me when I tried it on R2024b.
The code does have some (latent) bugs though:
I doubt that that code has ever actually done what its author intended. Probably they intended something like this:
for k = 1:4
p = sprintf('File Nr. %u auswaehlen.',k);
[info.name{k}, info.path{k}] = uigetfile('',p);
assert(~isequal(info.name{k},0),'Kein valides Inputfile ausgewählt')
info.vnr{k} = info.name{k}(1:5);
end
Respuesta aceptada
Más respuestas (0)
Ver también
Categorías
Más información sobre Develop Apps Using App Designer en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!