How to plot LSQCURVEFIT output
8 次查看(过去 30 天)
显示 更早的评论
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.
1 个评论
Adam Danz
2019-7-14
lsqcurvefit() produces parameter estimates to a function that you supply. Plug those parameter estimates (outputs) into the function to produce the optimal curve. (PS, TLDR; I didn't look through your files).
采纳的回答
Star Strider
2019-7-14
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.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Interpolation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!