Update automatically edit box when user enters values in other edit boxes
Show older comments
Hi, I've created a script with several edit boxes and I need that they interact with themselves and update its string values only when the end user enter data in some of them. This is part of my script:
%Edit boxes where the user inserts or changes data
e0 = uicontrol('Style','edit','Position',[150 105 80 20],'String','15'); %Default value, but user can change it.
e1 = uicontrol('Style','edit','Position',[150 80 80 20]);
e2 = uicontrol('Style','edit','Position',[150 55 80 20]);
e3 = uicontrol('Style','edit','Position',[150 20 80 20];
%Edit box that needs to be updated only when the user inputs data in the previous edit boxes.
e4 = uicontrol('Style','edit','Position',[285 140 50 20],'Enable','off');
And now I want to define a function or a callback to update automatically the value of the last edit box, along these lines:
h1 = get(e1,'String'); h2 = get(e2,'String');
h3 = str2num(h1) + str2num(h2);
v1 = str2num(get(e3,'String'));
var = str2num(get(e0,'String'));
v2 = num2str(v1*171233*((288+var)-0.00198*h3)^0.5/(288-0.00198*h3)^2.628);
set(e4,'String',v2);
Any help is welcome. Thanks in advance.
Accepted Answer
More Answers (1)
isdapi
on 26 Nov 2014
0 votes
Categories
Find more on Interactive Control and Callbacks in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!