# MATLAB: How to fit multiple datasets with one ore more formulas with the same parameters

## MATLAB: How to fit multiple datasets with one ore more formulas with the same parameters

fitting multiple data set with the same parameterslsqcurvefit

I have multiple data with the same Xdata (size 1×7) and different Ydata (Y1,Y2,Y3) all with size 1×7. I have to fit this data to one formula of the form:
x=a/(((1+(sqrt((b.^2).*Ypa+(Ype.^2)))./c.^d)
The totaal Ydata is combined in one matrix and then divided in parallel and perpendicular direction for the three different angles. This matrix has of length of 1×42 Y=[Y1pa Y2pa Y3pa Y1pe Y2pe Y3pe].. I have used several methods to try to find the values of the parameters so it will fits to all the three measurement data sets, but I have problems with the dimensions of the matrix. I try to solve it the following way:
``mf=@(C,Y)(C(1)./(((1+(sqrt((C(2)^2).*Y(1:21))+(Y(22:42).^2)))./C(3)).^C(4)));R1=lsqcurvefit(mf,[280,0.25,1,0.7],Xtotaal,Ytotaal);a=R1(1);b=R1(2);c=R1(3);d=R1(4);``
I have to fit this formula for the three data sets (X,Y1),(X,Y2) and (X,Y3). So I used the vectors Itotaal=[X X X] and Ytotaal=[Y1 Y2 Y3]. But when running this code following error occurs:
``Index exceeds matrix dimensions.Error in Final_fit_try>@(C,Y)(C(1)./(((1+(sqrt((C(2)^2).*Y(1:21))+(Y(22:42).^2)))./C(3)).^C(4)))Error in lsqcurvefit (line 199)            initVals.F = feval(funfcn_x_xdata{3},xCurrent,XDATA,varargin{:});Error in Final_fit_try (line 23)R1=lsqcurvefit(mf,[280,0.25,1,0.7],Xtotaal,Ytotaal);Caused by:    Failure in initial user-supplied objective function evaluation. LSQCURVEFIT cannot continue.``
What must be the size of the vectors Xtotaal and Ytotaal? I tried different sizes but the error still occurs.

``Xtotaal = x(:);Ytotaal = [Y1pa(:) Y2pa(:) Y3pa(:) Y1pe(:) Y2pe(:) Y3pe(:)];mf = @(C,Y)(C(1)./(((1+(sqrt((C(2)^2).*Y(:,1:3))+(Y(:,4:6).^2)))./C(3)).^C(4)));``