Testing if an input is numeric or character
2 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
Stephen23
2019-8-19
if isnan(Sbase_gerador)
...
end
3 个评论
Stephen23
2019-8-20
编辑:Stephen23
2019-8-20
"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!
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!