Edit box 'keypressfcn' does not refresh the Edit box, unless I am debugging the callback function
显示 更早的评论
I have the following code (I want to avoid non numeric input in the edit box):
hfig=figure(1);
hhh = uicontrol(hfig...
,'Style','edit'...
,'Position',[10 310 150 40]...
,'HorizontalAlignment', 'right'...
,'KeyPressFcn',@keyPressCallback...
);
function keyPressCallback(source,eventdata)
switch eventdata.Key
case 'return'
box_getnumber(source);
end
end
function box_getnumber(hhh)
nummer=get(hhh,'String');
if ~isempty(nummer)
nummer=cell2mat(regexp(nummer,'[0-9e.-+]','match'));
if ~isempty(nummer)
nummer=str2double(nummer);
hhh.String=num2str(nummer,'%15.5g');
end
end
end
This code does not update the Edit box content. If I put a breakpoint anywhere in the two functions then I continue the run, the Edit box refreshes.
What is wrong in the code? (I have tried 'drawnow', it does not work!)
Csaba
采纳的回答
更多回答(1 个)
Sahithi Kanumarlapudi
2020-8-27
Hi Csaba,
I have brought this issue to the notice of our developers. They will investigate the matter further.
And 'uieditfield'function could serve you as an alternative. The following code snippet is an example to create an edit field which will throw a warning on entering non-numeric data.
f = uifigure()
e = uieditfield(f,'numeric')
Hope this helps!
类别
在 帮助中心 和 File Exchange 中查找有关 Interactive Control and Callbacks 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!