MATLAB: Using lsqcurvefit without knowning the function

lsqcurvefitnonlinear curve fitting

This is what I understand from the matlab help
x = lsqcurvefit(@myfun,x0,xdata,ydata)
function F = myfun(x,xdata)
F = ... % Compute function values at x, xdata
The least square non-linear fit will match the ydata and the F-output by changing the x value.
My question is that " is xdata the input to calculate F?" Does xdata have to have the same size as ydata?
It is hard for me to apply lsqcurvefit to my problem. I have Xdata_e, Ydata_e from the experiments ( XYdata_e combines Xdata_e and Ydata_e) and I want to match with Xdata_s, Ydata_s from the simulation by changing the parameter x.
I have
function F = myfun(x,XYdata_s) % where XYdata_s contains Xdata_s and Ydata_s
giving the initial position X0 contains both x,y. Also giving time step, so on
The code will calculate Xdata_s, Ydata_s
F= the code that solves for Xdata_s and Ydata_s from simulation. Xdata_s is NOT using to calculate Ydata.
I set F=XYdata_s;
This is my lsqcurvefit
x = lsqcurvefit(@myfun,x0,XYdata_s,XYdata_e) % x0 is initial guess of x
I feel like there is something wrong in my code because XYdata_s is NOT the input to calculate F. Because XYdata_s is the matrix of my output that I want to match with XYdata_e. Basing on my code, the input is the initial position of x and y which does not have the same dimension as XYdata_e. The initial position X0 contains both x and y having the dimension of 6 x1. However, the dimension of XYdata_e has the dimension of 100 x 6. I dont know how to set it correctly. Please helps.
Any thoughts will be appreciated. Thank you.

Best Answer

However, the dimension of XYdata_e has the dimension of 100 x 6. I dont know how to set it correctly.
If the given target data XYdata_e has dimension 100 x 6, then F(x,XYdata_s) must always return an output array of dimension 100x6. That is the only restriction.