Borrar filtros
Borrar filtros

How to insert a function into a push button

2 visualizaciones (últimos 30 días)
Nadzri
Nadzri el 9 de Abr. de 2013
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

Respuesta aceptada

Mahdi
Mahdi el 9 de Abr. de 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;

Más respuestas (0)

Categorías

Más información sobre App Building en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by