Clear Filters
Clear Filters

How to insert a function into a push button

2 views (last 30 days)
Hello, I'm trying to make a GUI for solving integral using trapezoidal rule. So far, I've done until the calculate push button which gives an error of
??? Undefined function or variable 'x'.
Error in ==> Trapezoidal_rule>calculate_Callback at 81
calculate = trapz(x,equation)
Error in ==> gui_mainfcn at 96
feval(varargin{:});
Error in ==> Trapezoidal_rule at 42
gui_mainfcn(gui_State, varargin{:});
Error in ==> @(hObject,eventdata)Trapezoidal_rule('calculate_Callback',hObject,eventdata,guidata(hObject))
??? Error while evaluating uicontrol Callback
However, in the m.file I've specified the x value as
function value_n_Callback(hObject, eventdata, handles)
% hObject handle to value_n (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of value_n as text
% str2double(get(hObject,'String')) returns contents of value_n as a double
value_n = get(hObject, 'string');
h = (value_b - value_a)/ (value_n);
x = value_a:h:value_b;
How do I overcome this?
Your help is greatly appreciated

Accepted Answer

Mahdi
Mahdi on 9 Apr 2013
One of your problems might be that you are defining x in two different sections of the GUI. What you can do is pass the handles by using these lines and then calling x again into the other function, so you should write
handles.x=value_a:h:value_b;
guidata(hObject, handles)
Then, right before you run the calculate=trapz(x,equation), insert this line
x=handles.x;

More Answers (0)

Categories

Find more on App Building in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!