MATLAB: How to plot LSQCURVEFIT output

linelinspacelsqcurvefitplotting

I have almost finished writing a program that fits my data using lsqcurvefit and two different functions for different parts of the data. The only part remaining is plotting the fit (output) from the lsqcurvefit run. I have attached my code and some sample data. I tried using linspace and line functions to do the plot, but I get 'vectors must be the same length'. Data.m is the file to run. GlobChiSq.m has the two model functions. caclPinf.m, calcLambda.m, and calcD.m are used by GlobChiSq.m. The sample data: concentration.txt, current-washin-washout-100-cat.txt, time-washin-washout-100-cat.txt, and traceLength.txt should be imported as column vectors and transposed to row vectors, and the variables should be named concentration, current, time, and traceLength respectively. Could someone help me figure out the plotting? Data.m is where I try to plot lsqcurvefit result. I'm not sure what, exactly, should go in linspace and line to plot the curve fit result. Thanks!
Note: The current and time data files are too big to attach here. I can send them to the person that helps with this question. Just let me know how to send it to you.

Best Answer

It is not easy to follow your code.
In order to use the linspace result, you need to put ‘xdata’ in your ‘GlobalChiSq’ function for the independent variable, perhaps:
xgrid = linspace(0,386610,1271810);
line(xgrid,GlobChiSq(p,xdata,Co(1),Diff), 'Color', 'r');
My confusion has to do with these lines in ‘Data.m’:
[p,resnorm] = lsqcurvefit(@(p,t1) GlobChiSq(p,T,Co,Diff), startingVals, t1, ydata, lb, ub, options)
%[p,resnorm] = lsqcurvefit(@(p,t1) GlobChiSq(p,t1,Co,Diff), startingVals, t1, ydata, lb, ub, options)
the first of which appears to be incorrect, and the the second (the one you commented-out) appeaars to be correct.