How to plot LSQCURVEFIT output

조회 수: 13 (최근 30일)
Kelly McGuire
Kelly McGuire 2019년 7월 14일
댓글: Star Strider 2019년 7월 16일
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
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
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.
  댓글 수: 2
Kelly McGuire
Kelly McGuire 2019년 7월 16일
I was able to get the plotting to work. I have a new question about the same progam, but I will post it as a new question.
Star Strider
Star Strider 2019년 7월 16일
Noted.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Linear and Nonlinear Regression에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by