Is it possible to see the equation when I use 'shape preserving interpolant' to fit a curve in MATLAB 7.9 (R2009b)?

16 次查看(过去 30 天)
I am creating a plot and then in my figure File Menu>Tools> select 'Basic Fitting'. In the Basic Fitting GUI, on selecting any polynomial fit I can see the equation of the polynomial in the figure. I do not see any equation when I select 'shape preserving interpolant'.

采纳的回答

MathWorks Support Team
When you select 'shape-preserving interpolant' for fitting a curve, MATLAB uses a piecewise cubic Hermite interpolation (PCHIP) for fitting the data. Therefore, in the resulting fit, each pair of consecutive points is connected by a different cubic polynomial described with 4 coefficients. The following example will illustrate how to extract the coefficients from the plot.
First, create a data set and plot the data:
x = [1 2 4 7 8 9 10]';
y = [1 5 3 3 5 8 1'];
hf = plot(x,y,'o');
To create the fit:
1)  Go to "Tools > Basic Fitting" on the figure window
2)  Select "shape-preserving interpolant" from the list of Plot Fits
3)  Select the right arrow button at the bottom right corner of the figure
4)  Select the "Save to Workspace" button to save the fit to the workspace.
By default, the save prompt will suggest the name "fit" for the plot fit.
To view the coefficients and the points where the piecewise polynomials connect, execute:
fit.coeff.coefs
fit.coeff.breaks
Unfortunately, it is not possible to automatically display these equations on the plot, and this may not be practical when the plot contains many data points, and hence there are many piecewise polynomials in the resulting fit. However, you can execute the code below to examine the equations for each segment:
coeffs = fit.coeff.coefs;
breaks = fit.coeff.breaks;
for idx = 1:size(fit.coeff.coefs, 1)
eq{idx, 1} = sprintf('%.2fx^3 + %.2fx^2 + %.2fx + %.2f %.2f <= x < %.2f', coeffs(idx, :), breaks(idx:idx+1));
end
If you wish, you can add the equations to the plot using a text object, or an annotation textbox. For example:
legend('Location','SouthEast')
text(1.2, 6.6, eq)
You will need to adjust the x and y inputs to TEXT based on the axes limits of your plot.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Interpolation 的更多信息

标签

尚未输入任何标签。

产品


版本

R2009b

Community Treasure Hunt

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

Start Hunting!

Translated by