Constrain axis when fitting curve in polyfit?
3 views (last 30 days)
Show older comments
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
0 Comments
Answers (0)
See Also
Categories
Find more on Interpolation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!