MATLAB: Returning to start of statement if error

errorloopMATLAB

[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

Best Answer

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
Related Question