Calling functions from other functions
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Jan
le 21 Mar 2013
Modifié(e) : Jan
le 21 Mar 2013
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.
Réponses (1)
Jan
le 21 Mar 2013
Modifié(e) : Jan
le 21 Mar 2013
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.
Voir également
Catégories
En savoir plus sur Interpolation dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!