Select a radiobutton.Calculate derivation or integration.

4 views (last 30 days)
I did a guide.it 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)
end
% 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.

Accepted Answer

Matt Fig
Matt Fig on 7 Dec 2012
Edited: Matt Fig on 7 Dec 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));
else
b = int(sym(a));
end
set(handles.edit2, 'String', char(b));
  6 Comments
Matt Fig
Matt Fig on 7 Dec 2012
Edited: Matt Fig on 7 Dec 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',...
'menubar','none',...
'numbert','off',...
'resize','off',...
'pos',[100 100 300 150]);
S.tg = uicontrol('Style','toggle',...
'Units','pix',...
'Position',[10 10 130 130],...
'callback',@tg_callb,...
'fontsize',13,...
'fontweight','bold',...
'String','Integral');
S.ed = uicontrol('Style','edit',...
'Units','pix',...
'Position',[150 100 130 30],...
'String','x^2 + sin(x)');
S.pb = uicontrol('Style','push',...
'Units','pix',...
'Position',[150 10 130 80],...
'CallBack',@pb_callb,...
'String','Calculate');
movegui('center')
guidata(S.fh,S)
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(S.tg,'value') % Find state of the toggle
b = diff(sym(a));
else
b = int(sym(a));
end
set(S.ed, 'String', char(b));
guidata(S.fh,S)
function [] = tg_callb(varargin)
% Callback for the toggle.
S = guidata(gcbf); % Get the structure.
if get(S.tg,'value')
set(S.tg,'string','Derivative')
else
set(S.tg,'string','Integral')
end
oner
oner on 7 Dec 2012
İt is perfect example. I examined it. I understand my problem. thank you so . i did it :)

Sign in to comment.

More Answers (0)

Categories

Find more on Manage Design Data in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!