From: Anna Hayton on
I am trying to use nlinfit to find four unknown parameters. I have used a similar method before but now when I run the code I get the following error message

??? Error using ==> nlinfit at 117
The model function 'myfun' was not found.

Error in ==> findf>qfit at 24
a = nlinfit(t,y,'myfun',a);

Error in ==> findf at 13
a = qfit(xdata,ydata);


This is my code -

function [a z] = findf(x,y)

%the raw data
energy = [15 20 25 30 40 60 80 100 662 2000 6000]';
depth = [NaN NaN 137.6855 143.9123 144.7387 129.8625 119.9215 122.6316 104.6974 100.1030 95.7069]';

a = qfit(energy,depth);

function [a z] = qfit(t,y)
a = [0.0115 -2.0 4000000 -70];
a = nlinfit(t,y,'myfun',a);
z = myfun(a,t);

function f = myfun(a,t)
f = 100*(1-exp(-a(1)*(t-a(2))))*(1 + (a(3)/((t-a(4))^3)));

Any help appreciated