Azzera filtri
Azzera filtri

Select a radiobutton.Calculate derivation or integration.

2 visualizzazioni (ultimi 30 giorni)
I did a can calculate function. Than function is written by user in an edit text.My gui shows it at second edit text. problem is this. My gui has two radio button(derivation and integration). I want when user select one of them my program calculate function.if user select integration my program solves integration of function, if user select derivation my progtam solves derivation of function. What i can do ? My progtam :
% --- Executes when selected object is changed in uipanel1. function uipanel1_SelectionChangeFcn(hObject, eventdata, handles)
if(hObject == handles.radiobutton_derivation)
elseif(hObject == handles.radiobutton_integration)
% Update handles structure guidata(hObject, handles);
% hObject handle to the selected object in uipanel1 % eventdata structure with the following fields (see UIBUTTONGROUP) % EventName: string 'SelectionChanged' (read only) % OldValue: handle of the previously selected object or empty if none was selected % NewValue: handle of the currently selected object % handles structure with handles and user data (see GUIDATA)
What must i write in if and elseif ??
Thank you for answer.

Risposta accettata

Matt Fig
Matt Fig il 7 Dic 2012
Modificato: Matt Fig il 7 Dic 2012
If you put the code in SelectionChangeFcn, then the integral or derivative will be computed as soon as the user changes radio buttons. Is that really what you want?
If not, I would put the code in the callback where the calculation is made. For example in a pushbutton callback. Here is where you find the selectedobject property and use that in the IF statement.
a = get(handles.edit1,'String');
H = handles;
if H.radiobutton_derivation==get(H.uipanel1,'selectedob')
b = diff(sym(a));
b = int(sym(a));
set(handles.edit2, 'String', char(b));
  6 Commenti
Matt Fig
Matt Fig il 7 Dic 2012
Modificato: Matt Fig il 7 Dic 2012
Here is a simple example that uses a toggle button to do the same thing. Instead of asking for the state of the toggle button, you are asking which is the selected object...
function [] = gui_calculus()
% How to use symbolics and strings.
S.fh = figure('name','Calculus',...
'pos',[100 100 300 150]); = uicontrol('Style','toggle',...
'Position',[10 10 130 130],...
S.ed = uicontrol('Style','edit',...
'Position',[150 100 130 30],...
'String','x^2 + sin(x)');
S.pb = uicontrol('Style','push',...
'Position',[150 10 130 80],...
uicontrol(S.ed) % put the focus on func box.
function [] = pb_callb(varargin)
% Callback for the push button
S = guidata(gcbf); % Get the structure.
a = get(S.ed,'String');
if get(,'value') % Find state of the toggle
b = diff(sym(a));
b = int(sym(a));
set(S.ed, 'String', char(b));
function [] = tg_callb(varargin)
% Callback for the toggle.
S = guidata(gcbf); % Get the structure.
if get(,'value')
oner il 7 Dic 2012
İt is perfect example. I examined it. I understand my problem. thank you so . i did it :)

Accedi per commentare.

Più risposte (0)


Scopri di più su Manage Design Data 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