MATLAB Quick Start (8): Data Interpolation and Fitting

Data Interpolation and Fitting

1. Data interpolation

The one-dimensional interpolation function is interp1(), and its calling format is: Y1=interp1(X,Y,X1,method)

This statement will calculate the value of the function at X1 based on the values ​​of X,Y.

The method parameter is used to specify the interpolation method. There are four commonly used values:

(1) linear: linear interpolation

(2) nearest: nearest point interpolation

(3) pchip: Hermitian interpolation in 3 segments

(4) spline: 3 times spline interpolation

The two-dimensional interpolation function is interp2(), and its calling format is:

Z1=interp2(X,Y,Z,X1,Y1,method)

Among them, X, Y are two vectors, representing the sampling points of the two parameters, Z is the function value corresponding to the sampling points, X1, Y1 are two scalars or vectors, representing the points to be interpolated.

2. Data fitting

The fitting function is polyfit(), its function is to obtain the least squares fitting polynomial coefficients, and the calling format is:

P=polyfit(X,Y,m)

[P,S]=polyfit(X,Y,m)

[P,S,mu]=polyfit(X,Y,m): According to the sample data X and Y, generate an m-degree polynomial P and its error data S at the sampling point, mu is a binary vector, mu(1) is mean(X) and mu(2) is std(X)


Scan the QR code to follow the official account " Talk to You ", and reply to the keyword " Getting Started " in the background of the official account , and you can get the full version of the MATLAB PDF document! ! !

Guess you like

Origin blog.csdn.net/m0_64087341/article/details/123426794