- rmmissing to remove NaN values, but be sure to remove the matching data points from your XY array also.
- fillmissing to replace NaN values with a predefined constant, method, or function.
How to fit 3D surface to datasets (excluding specific datapoints) without Curve Fitting Toolbox
8 views (last 30 days)
Show older comments
Hi all,
I want to fit a 3D surface to my dataset using a gaussian function — however, some of my data is saturated and I would like to exclude DATA above a specific value in my fit without removing columns or rows from my data.
I do not have the Matlab Curve Fitting Toolbox. I understand the Curve Fitting Toolbox can exclude datapoints from the fit without having to remove full rows — this is what I'd like to do here. Rmmissing is not the solution I am looking for as it deletes full rows.
My current code works well when I leave the saturated data in:
[OUTPUT, ~, RESIDUALS, ~, ~, ~, ~] = lsqcurvefit(FIT_FUNCTION, GUESSES, XY, DATA, LWR_BND, UPR_BND, OPTS);
but when I change the saturated cells to NaN (i.e. DATA(DATA>1000) = NaN), I get the following error:
'Finite difference Jacobian at initial point contains Inf or NaN values. lsqcurvefit cannot continue.'
Is there a way to exclude data above a specific integer value from a 3D fit without deleting rows/columns from my data?
Is there another solution other than using lsqcurvefit that would work? I have been unable to resolve this so far.
Thank you in advance!
Below is what I am working with in terms of MATLAB version and toolboxes:
MATLAB Version 9.9 (R2020b)
Image Processing Toolbox Version 11.2 (R2020b)
Optimization Toolbox Version 9.0 (R2020b)
Signal Processing Toolbox Version 8.5 (R2020b)
EDIT: re-worded question for clarity based on two answers given up to now.
0 Comments
Accepted Answer
Joe Vinciguerra
on 6 Apr 2023
I would recommend using either:
Since you're trying to fit the data you probably don't want to use fillmissing, but that depends on your application and your dataset.
For more information: Missing Data in MATLAB - MATLAB & Simulink (mathworks.com)
7 Comments
Joe Vinciguerra
on 10 Apr 2023
The Curve Fitting Toolbox would be appropriate for fitting surfaces.
However, you would still need to remove the NaN values as I described above. You don't need to remove entire ros and columns, just the (x,y,z) tuple if one of the components is NaN as I described above.
More 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!