Do sfit and cfit objects carry the input x,y,z data? If not, why do they consume so much memory?

2 views (last 30 days)
Attached is an sfit obejct from a poly33 fit, generated with the cftool app. I am wondering why it consumes so much memory (3.3MB) considering that it only contains 10 coefficients, some formula text, and perhaps an additional 20 values for the confidence bounds. Does the sfit object contain the original x,y,z data used to generate the fit? That might account for the additional memory, but if so, is there a way to retrieve that data from the object?
load fittedmodel
fittedmodel
Linear model Poly33: fittedmodel(x,y) = p00 + p10*x + p01*y + p20*x^2 + p11*x*y + p02*y^2 + p30*x^3 + p21*x^2*y + p12*x*y^2 + p03*y^3 Coefficients (with 95% confidence bounds): p00 = -0.4888 (-0.5129, -0.4646) p10 = 0.04507 (0.04389, 0.04624) p01 = 0.1304 (0.125, 0.1359) p20 = 0.005239 (0.005174, 0.005304) p11 = -0.01134 (-0.01149, -0.01119) p02 = -0.009979 (-0.01038, -0.009575) p30 = 0.0005176 (0.0005155, 0.0005198) p21 = 0.0002514 (0.0002483, 0.0002546) p12 = 0.0005639 (0.0005586, 0.0005691) p03 = 0.0002402 (0.0002303, 0.0002501)
whos fittedmodel
Name Size Bytes Class Attributes fittedmodel 1x1 3338 sfit

Accepted Answer

Matt J
Matt J on 22 Nov 2023
Edited: Matt J on 22 Nov 2023
Never mind. I see now that the memory consumption is on ly 3.3KB, not MB. And I see from the test below that the data size does not affect the size of the fit object, so I don't think the fit object could be carrying the data around.
N=1e4;
[x,y]=deal(rand(N,1));
fobj1=fit(x,y,'poly1');
N=1e7;
[x,y]=deal(rand(N,1));
fobj2=fit(x,y,'poly1');
whos fobj1 fobj2
Name Size Bytes Class Attributes fobj1 1x1 740 cfit fobj2 1x1 740 cfit

More Answers (1)

Avadhoot
Avadhoot on 21 Nov 2023
Hi Matt,
I understand that you have created a “sfit” object using the “cftool” app. The object is created by the name, “fittedmodel”. As you have mentioned correctly, the large size of “fittedmodel” is due to the fact that it stores the original fitting data as the variables x,y and z. You can access all the attributes of the “fittedmodel” object by first loading the object into your base workspace as follows:
load fittedmodel
After executing this command, you will see all the variables defined in the "fittedmodel.mat" file in your workspace. You can access them directly from the base workspace itself.
Refer to the below documentation for more information on sfit” objects:
I hope it helps.

Categories

Find more on Linear and Nonlinear Regression in Help Center and File Exchange

Tags

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!