Prevent typing string in edit text
Mostra commenti meno recenti
I have a problem. I want to create a edit text and then when I type a string in it, it will display nothing like a empty. That is to say it allows only numbers. I found some ways but they use push button for checking. Please help me.
Thank you in advance.
Risposta accettata
Più risposte (3)
Walter Roberson
il 31 Mar 2016
0 voti
You can use a variation of http://www.mathworks.com/matlabcentral/fileexchange/24861-41-complete-gui-examples/content/GUI_37.m
Daveed Daveed
il 31 Lug 2022
Hello. i was walking around here and i thought the following solution might be usefull for future people (may be the past time traveler :) )
function prevent_string(textbox_control)
if textbox_control.String ~= "" && isnan(str2double(textbox_control.String))
textbox_control.String = "";
end
Walter Roberson
il 31 Lug 2022
These days you would use a
uieditfield('numeric')
which requires uifigure() (and will not work for traditional figures)
Categorie
Scopri di più su Creating, Deleting, and Querying Graphics Objects in Centro assistenza e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!