How to plot LSQCURVEFIT output

8 Ansichten (letzte 30 Tage)
Kelly McGuire
Kelly McGuire am 14 Jul. 2019
Kommentiert: Star Strider am 16 Jul. 2019
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 Kommentar
Adam Danz
Adam Danz am 14 Jul. 2019
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).

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Star Strider
Star Strider am 14 Jul. 2019
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 Kommentare
Kelly McGuire
Kelly McGuire am 16 Jul. 2019
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 am 16 Jul. 2019
Noted.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Interpolation finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by