Simple program with a formula

Hello everyone! Could anyone help me with a program using GUI: I have this simple formula x+y=z. I have an "edit text" for each x,y and z and I want the user to be able to write a number in "x" and a number in "y" and the result to come up in the "edit text" for z. Any help with the code?? I know it's simple, but if I learn how to do that I could go onto harder stuff. Thank you very much! Daniel

 채택된 답변

Caleb
Caleb 2012년 7월 16일

0 개 추천

function xyz
x = uicontrol('style','edit','units','normalized',...
'position',[.18 .5 .2 .2],'callback',@xCallbackFcn,'tag','x')
y = uicontrol('style','edit','units','normalized',....
'position',[.4 .5 .2 .2], 'callback',@yCallbackFcn,'tag','y')
z = uicontrol('style','edit','units','normalized',...
'position',[.62 .5 .2 .2],'tag','z')
set(x,'string',0)
set(y,'string',0)
set(z,'string',0)
function xCallbackFcn(hObject,eventdata)
x = str2double(get(findobj('tag','x'),'string'));
y = str2double(get(findobj('tag','y'),'string'));
z = x + y;
set(findobj('tag','z'),'string',z)
function yCallbackFcn(hObject,eventdata)
x = str2double(get(findobj('tag','x'),'string'));
y = str2double(get(findobj('tag','y'),'string'));
z = x + y;
set(findobj('tag','z'),'string',z)

댓글 수: 1

Dan
Dan 2012년 7월 18일
Thank you very very much for that. From this I can keep on learning! Thank you once again!

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Walter Roberson
Walter Roberson 2012년 7월 11일

0 개 추천

hint:
x = str2double( get(TheFirstEditHandle, 'String') );

카테고리

도움말 센터File Exchange에서 Text Data Preparation에 대해 자세히 알아보기

태그

질문:

Dan
2012년 7월 11일

Community Treasure Hunt

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

Start Hunting!

Translated by