Obtain equation for a curve of best fit
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (1)
dpb
el 12 de Mayo de 2016
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 comentarios
Ver también
Categorías
Más información sobre Interpolation en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!