How to plot LSQCURVEFIT output
6 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Kelly McGuire
el 14 de Jul. de 2019
Comentada: Star Strider
el 16 de Jul. de 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 comentario
Adam Danz
el 14 de Jul. de 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).
Respuesta aceptada
Star Strider
el 14 de Jul. de 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 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Interpolation en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!