Constrain axis when fitting curve in polyfit?

3 views (last 30 days)
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

Answers (0)

Categories

Find more on Interpolation in Help Center and File Exchange

Products


Release

R2019a

Community Treasure Hunt

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

Start Hunting!