Write a script 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). The script then prints the length of the string.

2 次查看(过去 30 天)
The getstr function is throwing me off

回答(1 个)

Chris C
Chris C 2014-3-17
编辑:Chris C 2014-3-17
This blurb of code is written to accept a string as an input. If you don't want it to accept only a string then you can get rid of the ,'s' portion. Enjoy :).
str = input('Plese enter your value: ','s');
while isempty(str)~=0
str = input('Plese enter a valid value: ','s');
end

类别

Help CenterFile Exchange 中查找有关 Install Products 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by