how can i assign few different calculation for a single pusshbutton

1 visualizzazione (ultimi 30 giorni)
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

Risposta accettata

nl2605
nl2605 il 19 Lug 2013
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 Commenti
hardip
hardip il 19 Lug 2013
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 il 19 Lug 2013
plus how can i show the answer? i have one statictext output.. answer_staticText

Accedi per commentare.

Più risposte (1)

nl2605
nl2605 il 19 Lug 2013
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 Commenti
hardip
hardip il 19 Lug 2013
owh my god. u sir are a genius.. it works. it finally works.. thank you so so much sir..

Accedi per commentare.

Categorie

Scopri di più su App Building in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by