- 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 次查看(过去 30 天)
显示 更早的评论
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 个评论
Stephen23
2025-4-10
编辑:Stephen23
2025-4-10
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
采纳的回答
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Develop Apps Using App Designer 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!