I have a global fit that I am trying to do. Where I have two data sets. dataset A and dataset B. Both A and B are vectors. I am trying to fit them using exponential fits. The two fit expressions are as follows:
fitA = a1*exp(-t/b1) + a2*exp(b2) + c
fitB = 1-(a1*exp(-t/b1) + a2*exp(b2) + c)
The following is the code I have written for it.
global_fit_data = [A; B]; % A and B are vectors of size 1X85
t = 0:10:840;global_fit_function = @(p) [p(3)*exp(-t/p(1))+p(4)*exp(-t/p(2))+p(5); 1-p(3)*exp(-t/p(1))-p(4)*exp(-t/p(2))-p(5)]; % Fitting functions
squared_errors = @(p) sum((global_fit_data - global_fit_function(p)).^2); % Parameter to be fit in fminsearch
options=optimset('MaxFunEvals', 1000000, 'MaxIter',1000000, 'Display', 'off', 'TolX', 1e-0012);fit = fminsearch(squared_errors,[50 700 0.1 1.1 1.3],options);
However, everytime I run this, I get the following error:
Subscripted assignment dimension mismatch.
Error in fminsearch (line 191)
fv(:,1) = funfcn(x,varargin{:});
Is there anything obviously wrong with how I am trying to utilize fminsearch?
P.S. I am using Matlab ver 2013b
Thanks!
Best Answer