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

 채택된 답변

Stephen23
Stephen23 2019년 8월 19일

0 개 추천

if isnan(Sbase_gerador)
...
end

댓글 수: 3

Hi Stephen, thank you very much for you help!!!
The code now has changed and now i got the right solution as you can see below.
I only have one more question, when the user entry with a character it opens the warning dialog box, but it doesn't stop the calculation and show some graphs.
Is it possible to stop the program?
Sbase_gerador = str2double(strrep((app.potencia.Value),',','.'));
teste_Sbase_gerador = isnan(Sbase_gerador);
if teste_Sbase_gerador==true
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
Stephen23
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!
Thank you again!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기

제품

질문:

2019년 8월 19일

댓글:

2019년 8월 20일

Community Treasure Hunt

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

Start Hunting!

Translated by