MATLAB: Nlinfit ERROR ( Matrix dimensions must agree.)

errorMATLABmatrixmatrix dimensionsnlinfit

I am trying to fit experimental data to using the nlinfit function and am getting the error:
Error using nlinfit (line 213)
Error evaluating model function '@(tao,n)(67.4.*1.2)./(2.*((100.*MnNiratedata.CurrentDensity(1:7)./25).*tao).^(n))'.
Error in Rate_Fitting (line 43)
x = nlinfit(R,Ni_D_Rate_Data,highRates_Model_Fit,b0)
Caused by:
Matrix dimensions must agree.
I have attempted to use the whos function to check all of my input matrix sizes and all are [7×1]. Attached is the code that I am trying to run. A sample data set that I am trying to fit is:
Rate = [100,180,260,340,400,800,1200]
Ni_D_Rate_Data = [100, 96, 93.6,93, 90, 85, 80]
where Rate would be my x variable and Ni_D_Rate_Data would be my y variable.
Any insight is much appreciated
%Data
discharge_Data = MnNiratedata;
% fractional charge discharge rate R = (I/M)/(Q/M)E
Rate = 100*MnNiratedata.CurrentDensity(1:7)./25;
whos R
% Q/M = Specific capacity data
Ni_D_Rate_Data = MnNiratedata.NiHCF_Discharge(1:7);
whos Ni_D_Rate_Data
% Qm = low-rate specific capacity
Qm_Ni_Discharging = 67.4*1.2; % specific capacity of NiHCF @ 25 mAg-1 (cap * 1.2)
whos Qm_Ni_Discharging
%Model to fit NiHCF
Model_Fit = @(tao,n) (67.4.*1.2).* (1-((R.*tao).^n)).*(exp(-1./(R.*tao).^n));
% starting guess for model parameters [tao,n]
b0 = [0.002; 0.8];
% perform a nonlinear regression)
x = nlinfit(R,Ni_D_Rate_Data,highRates_Model_Fit,b0)

Best Answer

Try this:
%Model to fit NiHCF
% % % MAPPING: tao = b(a), n = b(2)
Model_Fit = @(b,R) (67.4.*1.2).* (1-((R.*b(1)).^b(2))).*(exp(-1./(R.*b(1)).^b(2)));
% starting guess for model parameters [tao,n]
b0 = [0.002; 0.8];
% perform a nonlinear regression)
x = nlinfit(R,Ni_D_Rate_Data,Model_Fit,b0)
The objective function for curve-fitting optimization functions requires that the parameter vector be the first argument, and the independent variable the second. (It is the same across all the Toolboxes.) See modelfun in the the nlinfit documentation.
.