How to insert a function into a push button
1 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
Mahdi
2013-4-9
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;
0 个评论
更多回答(0 个)
另请参阅
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!