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

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

댓글을 달려면 로그인하십시오.

 채택된 답변

Bhaskar R
Bhaskar R 2019년 11월 20일

1 개 추천

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

Philippe Lebel
Philippe Lebel 2019년 11월 20일
You stole my upvote! i want my money back!
Bhaskar R
Bhaskar R 2019년 11월 20일
My pleasure !!!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Data Import and Export에 대해 자세히 알아보기

제품

릴리스

R2019b

질문:

2019년 11월 20일

댓글:

2019년 11월 20일

Community Treasure Hunt

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

Start Hunting!

Translated by