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 件)
参考
カテゴリ
Help Center および File Exchange で Migrate GUIDE Apps についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!