The following script calls a function getstr that prompts the user for a string, error-checking until the user enters something (the error would occur if the user just hits the Enter key without any other characters first)
belongs to book: MATLAB: A Practical Introduction to Programming and Problem Solving|Stormy Attaway|Fourth Edition| Chapter number:7| Question number:2.7
All Answers
total answers (1)
Ch7Ex2.m
thestring = getstr();
fprintf('Thank you, your string is %d characters long\n', ...
length(thestring))
getstr.m
function outstr = getstr
% Prompts the user until the user enters a string
% with a length > 0
% Format of call: getstring or getstring()
outstr = input('Please enter a string: ', 's');
while isempty(outstr)
outstr = input('PLEASE enter a string: ', 's');
end
end
need an explanation for this answer? contact us directly to get an explanation for this answer