Returning to start of statement if error
21 views (last 30 days)
Show older comments
[file,path] = uigetfile('*.CSV'); % Prompting the user to select a .CSV file from their directory
if isequal(file,0)
errordlg('User has selected Cancel', 'File Selection Error');
else
disp(['User selected ', fullfile(path,file)]);
end
Hi For the above code, I would like to return to the start of the code again if the user selects cancel. At the minute an error msg appears but the code ends.
Any ideas?
Thanks
1 Comment
Philippe Lebel
on 20 Nov 2019
here is my shot at it:
while(1)
% the famous start of the code i think you are talking about
[file,path] = uigetfile('*.CSV'); % Prompting the user to select a .CSV file from their directory
if isequal(file,0)
errordlg('User has selected Cancel', 'File Selection Error');
else
disp(['User selected ', fullfile(path,file)]);
break;
end
end
Accepted Answer
Bhaskar R
on 20 Nov 2019
while 1
[file,path] = uigetfile('*.CSV'); % Prompting the user to select a .CSV file from their directory
if isequal(file,0)
continue;
% errordlg('User has selected Cancel', 'File Selection Error');
else
disp(['User selected ', fullfile(path,file)]);
break;
end
end
2 Comments
More Answers (0)
See Also
Categories
Find more on Bartlett in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!