how can i assign few different calculation for a single pusshbutton
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
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
0 Commenti
Risposta accettata
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!
Più risposte (1)
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
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!