promptMessage = sprintf('Select your text file on the next dialog box.');
titleBarCaption = 'Continue?';
buttonText = questdlg(promptMessage, titleBarCaption, 'OK', 'Cancel', 'OK');
if contains(buttonText, 'Cancel', 'IgnoreCase', true)
return;
end
startingFolder = pwd;
if ~isfolder(startingFolder)
startingFolder = pwd;
end
defaultFileName = fullfile(startingFolder, '*.txt');
[baseFileName, folder] = uigetfile(defaultFileName, 'Select a file');
if baseFileName == 0
return;
end
fullFileName = fullfile(folder, baseFileName)
fileID = fopen(fullFileName, 'rt');
textLine = fgetl(fileID);
lineCounter = 1;
while ischar(textLine)
userPrompt = sprintf('%s (type only Enter to quit now): ', strtrim(textLine));
userResponse = input(userPrompt, 's');
if isempty(userResponse)
break;
end
fprintf('You entered %s.\n', userResponse);
textLine = fgetl(fileID);
lineCounter = lineCounter + 1;
end
fclose(fileID);
Best Answer