Calling functions from other functions

조회 수: 2 (최근 30일)
KV
KV 2013년 3월 21일
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
KV
KV 2013년 3월 21일
Anyone?
Jan
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
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.
  댓글 수: 1
KV
KV 2013년 3월 21일
Hi Jan, thanks for your response. It is not a nested function. I did try declaring x and y as input arguments in function hit_ok_callback as well but i get the error: Error using test>hit_ok_Callback Not enough input arguments.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Interpolation에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by