Constrain axis when fitting curve in polyfit?

2 visualizaciones (últimos 30 días)
Laura Braun
Laura Braun el 30 de Mzo. de 2020
Hi,
I am new to matlab and fitting a polynomial to a dataset using polyfit. I have managed to fit the data and forcing it to go through (0,0) using polyfitzero code. However, I want the polyfit curve to always stay positive (i.e. y>=0 at all times).
Is there a way to constrain the y axis to stay above 0?
My code:
function[Rsq]=Rfig(CT, log)
scatter(CT,log); %scatter plot of raw data
[p,S,mu] = polyfitZero(CT, log, 3);
f = polyval(p,CT,[],mu);
hold on
plot(CT,f)
Rsq=1 - (S.normr/norm(log - mean(log)))^2 %calculate Rsquared
end
Many thanks

Respuestas (0)

Categorías

Más información sobre Interpolation en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by