Prevent typing string in edit text
Ältere Kommentare anzeigen
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.
Akzeptierte Antwort
Weitere Antworten (3)
Walter Roberson
am 31 Mär. 2016
0 Stimmen
You can use a variation of http://www.mathworks.com/matlabcentral/fileexchange/24861-41-complete-gui-examples/content/GUI_37.m
Daveed Daveed
am 31 Jul. 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
am 31 Jul. 2022
These days you would use a
uieditfield('numeric')
which requires uifigure() (and will not work for traditional figures)
Kategorien
Mehr zu Creating, Deleting, and Querying Graphics Objects finden Sie in Hilfe-Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!