Surface Fit off in one corner of a polynomial surface

1 回表示 (過去 30 日間)
matthias daeumer
matthias daeumer 2021 年 11 月 4 日
回答済み: Vinayak 2024 年 5 月 23 日
I am trying to fit a surface to some noisy data so that this surface can be subtracted from the data to normalize the background. However when I fit the fit is good except at one corner where it is way off (see picture). Does anyone have a suggestion on how to get the surface to fit the data in the corner more closely.
Poly 55 seems to work better than poly44 or poly 33.
Another option i did was to break the 2D matrix into vectors and fit a curve to each row vector which worked very well with poly4. But I would like to solve this problem with surface fitting.
Thanks.
The code I am using is:
[f gof] = fit([xdata',ydata'],zdata', 'poly55')
plot(f, [xdata',ydata'],zdata')

回答 (1 件)

Vinayak
Vinayak 2024 年 5 月 23 日
Hi matthias,
As you want to fit some noisy data with problematic regions in the corners, I would recommend weighted fitting as you are aware of regions of concern. Assigning more weights to significant data points will make the fitting algorithm prioritize these points.
You can get the indices of the regions using conditional indexing, and later assign higher weights to them. You can use the same poly55 or another similar fitting algorithm to get a better fit.
% Find indices
corner_indices = (xdata < corner_x_threshold) & (ydata < corner_y_threshold);
% Assign weights
weights = ones(size(zdata));
weights(corner_indices) = 10; % Increase the weight for the corner region
% Perform the fit with weights
[f, gof] = fit([xdata', ydata'], zdata', 'poly55', 'Weights', weights);
This should resolve the issue you are facing with underfitting around the corners.

カテゴリ

Help Center および File ExchangeGet Started with Curve Fitting Toolbox についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by