Borrar filtros
Borrar filtros

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.

3 visualizaciones (últimos 30 días)
The getstr function is throwing me off

Respuestas (1)

Chris C
Chris C el 17 de Mzo. de 2014
Editada: Chris C el 17 de Mzo. de 2014
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

Community Treasure Hunt

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

Start Hunting!

Translated by