Returning to start of statement if error

[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 Kommentar

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

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

Bhaskar R
Bhaskar R am 20 Nov. 2019

1 Stimme

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 Kommentare

Philippe Lebel
Philippe Lebel am 20 Nov. 2019
You stole my upvote! i want my money back!
Bhaskar R
Bhaskar R am 20 Nov. 2019
My pleasure !!!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Data Import and Export finden Sie in Hilfe-Center und File Exchange

Produkte

Version

R2019b

Gefragt:

am 20 Nov. 2019

Kommentiert:

am 20 Nov. 2019

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by