How can I access the String properties of edit uicontrols and use them to calculate and send the result to a text uicontrol?

24 views (last 30 days)
Here is the code I've written thus far:
figure('Position',[150 100 900 400]);
but01=uicontrol('Style','pushbutton', ...
'Position',[5 10 90 40],'String','Close','Callback',...
'close(fig01)');
uicontrol('Style','edit','Position',...
[50 200 60 60]);
uicontrol('Style','edit','Position',...
[150 200 60 60]);
uicontrol('Style','edit','Position',...
[250 200 60 60]);
uicontrol('Style','edit','Position',...
[350 200 60 60]);
uicontrol('Style','pushbutton','Position',...
[550 200 90 90],'String','Calculate',...
'Callback','text1.String=edit1.String');
uicontrol('Style','text','Position',[650 200 100 100],'String',answer);
I am doing the GUI with code because GUIDE just didn't make sense to me, even after reading the docs...
I am trying to make a simple GUI that can multiply user input numerical values in my school's biotech lab. This one is heading toward calculating reagents needed for various solutions using dimensional analysis. Since most of these analyses are structured similarly, I thought this could be a good way to check our work.
I am very grateful for any suggestions, this is my first venture into developing software for bio labs.

Answers (1)

Grzegorz Knor
Grzegorz Knor on 16 Sep 2011
Use set and get command. Look at simple example:
function test
figure('Position',[150 100 900 400]);
uicontrol('Style','pushbutton','Position',...
[5 10 90 40],'String','Close','Callback','close(gcf)');
h1 =uicontrol('Style','edit','Position',[50 200 60 60]);
uicontrol('Style','edit','Position',[150 200 60 60]);
uicontrol('Style','edit','Position',[250 200 60 60]);
uicontrol('Style','edit','Position',[350 200 60 60]);
uicontrol('Style','pushbutton','Position',...
[550 200 90 90],'String','Calculate','Callback',@simple_callback);
h2 = uicontrol('Style','text','Position',[650 200 100 100]);
function simple_callback(src,evnt)
answer = get(h1,'String');
set(h2,'String',answer')
end
end

Categories

Find more on Migrate GUIDE Apps in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!