Testing if an input is numeric or character

3 views (last 30 days)
Hi folks, i'm implementing a software on appDesigner and i want to prevent wrong entries from users.
I've tried to use the folowing code but it's not working. My gol would be, check if the user entered with a number or character. If it's a number then OK, otherwise open a warning dialog box informing the error and then stop the program.
I don't know how to get the logical answer of "teste_potencia" and use it!
The way i've writed it's not working.
Sbase_gerador = str2double(strrep((app.potencia.Value),',','.'));
teste_potencia = isnumeric(Sbase_gerador)
if ~teste_potencia
opts= struct('WindowStyle','modal','Interpreter','tex');
potencia_incorreta = warndlg('\fontsize{11}Caracteres diferentes de números não são aceitos.',...
'Entrada incorreta de dados', opts);
app.potencia.Value='0';
end

Accepted Answer

Stephen23
Stephen23 on 19 Aug 2019
if isnan(Sbase_gerador)
...
end
  3 Comments
Stephen23
Stephen23 on 20 Aug 2019
Edited: Stephen23 on 20 Aug 2019
"Is it possible to stop the program?"
Depending on how you want to "stop" the program, one of these might work for you:
  • return
  • break
  • error
  • keyboard
  • if followed by some other code...
"thank you very much for you help!!!"
My pleasure! If it helped you don't forget to accept my answer!

Sign in to comment.

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!