Calling functions from other functions
2 次查看(过去 30 天)
显示 更早的评论
Hi, I am developing a simple GUI. When a user presses a button, I want the code to initiate the curve fitting. I hae one function for GUI, and was looking to use another function which contains code for curve fitting, and the curve fitting tool function is called from GUI function. The code I have is below:
function hit_ok_Callback(hObject, eventdata, handles);
createFit(x, y);
end
function createFit(x, y)
ft = fittype ('poly4');
n[xdata, ydata] = prepareCurveData(x, y);
c = fit(xdata,ydata,ft);
However i get error saying i am using undefined function or variable. "Error in test>hit_ok_Callback. createFit(x, y)"
If I call the file containing just createFit function from command window, it works fine. What am I doing wrong in the way I am calling the function?
2 个评论
Jan
2013-3-21
编辑:Jan
2013-3-21
A bumping after 1 hour is not friendly. When the readers do not know an answer, reading the question again is a waste of time only. I suggest to limit bumping on more than 24 hours.
Please post a copy of the message, because paraphrased messages usually loose important details.
回答(1 个)
Jan
2013-3-21
编辑:Jan
2013-3-21
In this command:
createFit(x, y)
you get the message "undefined function or variable", but in the command window, this command works.
Then I guess, that createFit is a well known function, but x and/or y are not. The function header function hit_ok_Callback(hObject, eventdata, handles) does not contain these variables, but perhaps it is a nested function and you forgot to explain this. But even then, these variables are not declared according to the error message.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Interpolation 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!