Unrecognized function or variable ” ” , when I use my function
Hi,
I write some function that will make a fit for my data. this is my function:
function Xmax = fit_function(x,y)
X1 = x(x>0.5 & x<2);
Y1 = y(x>0.5 & x<2);
% ymax calculated analytically with Wolfram Mathematica
ymax = @(b) (2-b(2)/b(1))*(2*b(1)/b(2)-1)^(-b(2)/2/b(1));
modelfun = @(b,x) b(3)/ymax(b)*exp((x-b(4))*(b(1)-b(2))).*sech(b(1)*(x-b(4)));
bguess=[78, 10, peaks(1),x(t_peaks(1))];
% [alpha, beta, amplitude, x offset]
% 78 and 10 were calculated by cftool (after given there a guess of 80,20)
beta = nlinfit(X1, Y1, modelfun, bguess);
fittedCurve = modelfun(beta, X1);
Xmax=log(-1+(2*beta(1)/beta(2)));
when I apply this function on some data, I have a problem in the line of bguess.
The function is able to read the "peaks(1)" variable, but not the t_peaks(1) variable. both of them save in the workspace, and slao both of them is double file.
as I say in the summary, the error is:
>> Xmax=fit_function(x,y);
Unrecognized function or variable ‘t_peaks’.
Error in fit_function (line 12)
bguess=[78, 10, peaks(1), x(t_peaks(1))];
why is append?
It’s strange that it can read one of the variables and not the other..
Thanks!(:Hi,
I write some function that will make a fit for my data. this is my function:
function Xmax = fit_function(x,y)
X1 = x(x>0.5 & x<2);
Y1 = y(x>0.5 & x<2);
% ymax calculated analytically with Wolfram Mathematica
ymax = @(b) (2-b(2)/b(1))*(2*b(1)/b(2)-1)^(-b(2)/2/b(1));
modelfun = @(b,x) b(3)/ymax(b)*exp((x-b(4))*(b(1)-b(2))).*sech(b(1)*(x-b(4)));
bguess=[78, 10, peaks(1),x(t_peaks(1))];
% [alpha, beta, amplitude, x offset]
% 78 and 10 were calculated by cftool (after given there a guess of 80,20)
beta = nlinfit(X1, Y1, modelfun, bguess);
fittedCurve = modelfun(beta, X1);
Xmax=log(-1+(2*beta(1)/beta(2)));
when I apply this function on some data, I have a problem in the line of bguess.
The function is able to read the "peaks(1)" variable, but not the t_peaks(1) variable. both of them save in the workspace, and slao both of them is double file.
as I say in the summary, the error is:
>> Xmax=fit_function(x,y);
Unrecognized function or variable ‘t_peaks’.
Error in fit_function (line 12)
bguess=[78, 10, peaks(1), x(t_peaks(1))];
why is append?
It’s strange that it can read one of the variables and not the other..
Thanks!(: Hi,
I write some function that will make a fit for my data. this is my function:
function Xmax = fit_function(x,y)
X1 = x(x>0.5 & x<2);
Y1 = y(x>0.5 & x<2);
% ymax calculated analytically with Wolfram Mathematica
ymax = @(b) (2-b(2)/b(1))*(2*b(1)/b(2)-1)^(-b(2)/2/b(1));
modelfun = @(b,x) b(3)/ymax(b)*exp((x-b(4))*(b(1)-b(2))).*sech(b(1)*(x-b(4)));
bguess=[78, 10, peaks(1),x(t_peaks(1))];
% [alpha, beta, amplitude, x offset]
% 78 and 10 were calculated by cftool (after given there a guess of 80,20)
beta = nlinfit(X1, Y1, modelfun, bguess);
fittedCurve = modelfun(beta, X1);
Xmax=log(-1+(2*beta(1)/beta(2)));
when I apply this function on some data, I have a problem in the line of bguess.
The function is able to read the "peaks(1)" variable, but not the t_peaks(1) variable. both of them save in the workspace, and slao both of them is double file.
as I say in the summary, the error is:
>> Xmax=fit_function(x,y);
Unrecognized function or variable ‘t_peaks’.
Error in fit_function (line 12)
bguess=[78, 10, peaks(1), x(t_peaks(1))];
why is append?
It’s strange that it can read one of the variables and not the other..
Thanks!(: function, variable MATLAB Answers — New Questions