I have some matlab code that I want to run in Octave. There's a function that does not work for octave, which is fittype. I have been googleing to find equivalent functions in Octave but to no avail.
I will post the code of that function to clarify the issue.
function bn = createFit2(b8,bi)
% --- Plot data that was originally in data set "bi vs. b8"
b8 = b8(:);
bi = bi(:);
% --- Create fit "fit"
ok_ = isfinite(b8) & isfinite(bi);
if ~all( ok_ )
warning( 'GenerateMFile:IgnoringNansAndInfs',...
'Ignoring NaNs and Infs in data.' );
end
ft_ = fittype('poly1');
% Fit this model using new data
cf_ = fit(b8(ok_),bi(ok_),ft_);
bn = cf_.p1;
% disp(cf_.p1)
This is part of the Curve Fitting Toolbox and I doubt you will find an equivalent for Octave. However, because you are trying to fit a first-order polynomial, it is rather straightforward to write the fitting by hand (you are only looking for the two polynomial coefficients), or even use the polyfit
function.
I came up with the following code. It is not giving me the same results but, I am still trying to understand what I am doing and what the output parameters are. There's the line bn=cf_.p1 in the matlab code. I assume is the property p1 of the object cf_, of the class fitobject.
function bn = createFit2(b8,bi)
% --- Plot data that was originally in data set "bi vs. b8"
b8 = b8(:);
bi = bi(:);
% --- Create fit "fit"
ok_ = isfinite(b8) & isfinite(bi);
if ~all( ok_ )
warning( 'GenerateMFile:IgnoringNansAndInfs',...
'Ignoring NaNs and Infs in data.' );
end
ft_ = 1 %orden del polinomio
% Fit this model using new data
cf_ = polyfit(b8(ok_),bi(ok_),ft_);
bn = cf_(1);
cf_ %muestra el valor de cf cada vez que ejecuta la función
% disp(cf_.p1)
My research is now on figuring which of the octave output is equivalent to the p1 from the cf_ MatLab fitobject.
Trial and error method showed me that indeed cf_.1 is cf_(1) in the resulting vector from fitting function fit (Matlab) and polyfit(Octave). The other thing I figured out was the polynomial orther was 1 instead of 2, wich I wasn't aware of.
Thanks all for your advices. You put me on the right track.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.