Obtain equation for a curve of best fit
조회 수: 3 (최근 30일)
이전 댓글 표시
I'm trying to use the Matlab function "fit" to obtain a curve of best fit for some experimental data. However the x-axis has shifted to to zero, when the data actually starts at 225.
Does anyone know why this is the case?
%%Extinction coefficient models
close all; clear all; clc;
%%1) STRATUM CORNEUM
load beta_carotene_extinction.txt
wavelength1 = beta_carotene_extinction(1:end,1); % Wavelength (nm)
extinction1 = beta_carotene_extinction(1:end,2); % Molar Extinction (cm-1/M)
% Find fitting function
fitobject1 = fit(wavelength1, extinction1, 'poly9');
% Comparison plots
figure, subplot(2,1,1), plot(wavelength1, extinction1)
xlabel('Wavelength (nm)'), ylabel('Molar Extinction cm^-^1/M')
title('Experiment data')
subplot(2,1,2), plot(fitobject1(wavelength1))
xlabel('Wavelength (nm)'), ylabel('Molar Extinction cm^-^1/M')
title('Curve of best fit')
Also, is there a better way than using polynomials for this kind of data? I'm just using polynomials because Matlab readily gives the you the polynomial coefficients and equation, so I can use it in another file.
EDIT: Totally forgot that no one is going to have access to the data. I've embedded the plot below.

댓글 수: 0
답변 (1개)
dpb
2016년 5월 12일
subplot(2,1,2), plot(fitobject1(wavelength1))
is plotting against the ordinal number of the array; to just plot over the range use (I think)
subplot(2,1,2), plot(fitobject1)
You can get comparison in the same plot which is often easiest to evaluate from as
subplot(2,1,2), plot(fitobject1,wavelength1,extinction1)
As for the second question, I'd suggest the 'cubicinterp' piecewise cubic interpolation would be better than high-order polynomial. The thing with using the cfit object is that the internals of the model are pretty much hidden so it's no harder to pass one type over another.
댓글 수: 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!