how can i assign few different calculation for a single pusshbutton

조회 수: 1 (최근 30일)
hye. i have to design a program to calculate the Op-amp circuits's Voltage gain.here is a brief idea of how this program should be. when the user initiates the program, there will be a popupmenu (with three different choices or types of circuits), three edit_text inputs and a calculate_pushbutton. user selects the type of circuit in the popupmenu and keys in the 3 different values example like A B C. hw can i program the code below to have it calculate the values using different formulas with respect to the circuit type. example like if the user selects circuit one and keys in the value the calculate_pushbutton should calculate using the formula A/B. and if user selects circuit 2, A*C. i have done the program to get data from user in the edit_Text. and also a reset button. but now the problem is how can i assign three different formulas in the calculate_pushbutton. below is the codings i made to calculate. but it doesnt work.
switch get(handles.popupmenu,'Value')
case 1
A = get(input1_editText,'String');
B = get(input2_editText,'String');
C = get(input3_editText,'String'));
total = str2num(A)/str2num(B);
answer=num2str(total);
set(handles.answer_staticText,'String',answer;
case 2
A = get(input1_editText,'String');
B = get(input2_editText,'String');
C = get(input3_editText,'String'));
total = str2num(A)*str2num(C);
answer=num2str(total);
set(handles.answer_staticText,'String',answer;
set
otherwise
end
thank you for your help

채택된 답변

nl2605
nl2605 2013년 7월 19일
In the callback function of the Push Button, you can use val = get(handles.popupmenu,'Value') and then use an if else statement like:
if val==1
A = get(input1_editText,'String');
B = get(input2_editText,'String');
total = str2num(A)/str2num(B);
elseif val==2
A = get(input1_editText,'String');
C = get(input3_editText,'String');
total = str2num(A)*str2num(C);
and so on.. Hope this helps!
  댓글 수: 2
hardip
hardip 2013년 7월 19일
i tried the codes that u have mentioned. this is how my code for the popupmenu looks like:
switch get(handles.popupmenu1,'Value')
case 1
set(handles.calculate_pushbutton,'Value');
case 2
set(handles.calculate_pushbutton,'Value');
case 3
set(handles.calculate_pushbutton,'Value');
otherwise
end
and this is the code for the calculate pushbutton. (i edited the previous inputs with the original one). i still cun run it.
val = get(handles.popupmenu,'Value')
if val==1
Ve = get(input1_editText,'String');
Vc = get(input2_editText,'String');
Vb = get(input3_editText,'String');
total = str2num(Vc)/str2num(Vb);
answer=num2str(total);
elseif val==2
Ve = get(input1_editText,'String');
Vc = get(input2_editText,'String');
Vb = get(input3_editText,'String');
total = str2num(Ve)/str2num(Vb);
answer=num2str(total);
else val==3
Ve = get(input1_editText,'String');
Vc = get(input2_editText,'String');
Vb = get(input3_editText,'String');
total = str2num(Ve)/str2num(Vc);
answer=num2str(total);
thank u for your help..
hardip
hardip 2013년 7월 19일
plus how can i show the answer? i have one statictext output.. answer_staticText

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

추가 답변 (1개)

nl2605
nl2605 2013년 7월 19일
Follow this link to use pop up menus the right way.
It should work.
Also, if you want to dispay data in static text use:
set(handles.statictext,'String',answer);
Hope this helps.
  댓글 수: 9
hardip
hardip 2013년 7월 19일
owh my god. u sir are a genius.. it works. it finally works.. thank you so so much sir..

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

카테고리

Help CenterFile Exchange에서 Platform and License에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by