help with smooth curve

조회 수: 9 (최근 30일)
Felix Obite
Felix Obite 2022년 9월 19일
댓글: Voss 2022년 9월 22일
I need help with smoothing the above curve. I plotted the curve from a loaded data and tried different smoothing and fitting function but its not smoothing. I need a smooth curve.

답변 (2개)

Sam Chak
Sam Chak 2022년 9월 19일
@Felix Obite, Have you looked into interp1() function?
Check out the first example:
help interp1
INTERP1 1-D interpolation (table lookup) Vq = INTERP1(X,V,Xq) interpolates to find Vq, the values of the underlying function V=F(X) at the query points Xq. X must be a vector. The length of X is equal to N. If V is a vector, V must have length N, and Vq is the same size as Xq. If V is an array of size [N,D1,D2,...,Dk], then the interpolation is performed for each D1-by-D2-by-...-Dk value in V(i,:,:,...,:). If Xq is a vector of length M, then Vq has size [M,D1,D2,...,Dk]. If Xq is an array of size [M1,M2,...,Mj], then Vq is of size [M1,M2,...,Mj,D1,D2,...,Dk]. Vq = INTERP1(V,Xq) assumes X = 1:N, where N is LENGTH(V) for vector V or SIZE(V,1) for array V. Interpolation is the same operation as "table lookup". Described in "table lookup" terms, the "table" is [X,V] and INTERP1 "looks-up" the elements of Xq in X, and, based upon their location, returns values Vq interpolated within the elements of V. Vq = INTERP1(X,V,Xq,METHOD) specifies the interpolation method. The available methods are: 'linear' - (default) linear interpolation 'nearest' - nearest neighbor interpolation 'next' - next neighbor interpolation 'previous' - previous neighbor interpolation 'spline' - piecewise cubic spline interpolation (SPLINE) 'pchip' - shape-preserving piecewise cubic interpolation 'cubic' - cubic convolution interpolation for uniformly-spaced data. This method does not extrapolate and falls back to 'spline' interpolation for irregularly-spaced data. NOTE: 'cubic' changed in R2020b to perform cubic convolution. In previous releases, 'cubic' was the same as 'pchip'. 'v5cubic' - same as 'cubic' 'makima' - modified Akima cubic interpolation Vq = INTERP1(X,V,Xq,METHOD,'extrap') uses the interpolation algorithm specified by METHOD to perform extrapolation for elements of Xq outside the interval spanned by X. Vq = INTERP1(X,V,Xq,METHOD,EXTRAPVAL) replaces the values outside of the interval spanned by X with EXTRAPVAL. NaN and 0 are often used for EXTRAPVAL. The default extrapolation behavior with four input arguments is 'extrap' for 'spline', 'pchip' and 'makima', and EXTRAPVAL = NaN (NaN+NaN*1i for complex values) for the other methods. PP = INTERP1(X,V,METHOD,'pp') is not recommended. Use griddedInterpolant instead. PP = INTERP1(X,V,METHOD,'pp') uses the interpolation algorithm specified by METHOD to generate the ppform (piecewise polynomial form) of V. The method may be any of the above METHOD except for 'v5cubic' and 'makima'. PP may then be evaluated via PPVAL. PPVAL(PP,Xq) is the same as INTERP1(X,V,Xq,METHOD,'extrap'). For example, generate a coarse sine curve and interpolate over a finer abscissa: X = 0:10; V = sin(X); Xq = 0:.25:10; Vq = interp1(X,V,Xq); plot(X,V,'o',Xq,Vq,':.') For a multi-dimensional example, we construct a table of functional values: X = [1:10]'; V = [ X.^2, X.^3, X.^4 ]; Xq = [ 1.5, 1.75; 7.5, 7.75]; Vq = interp1(X,V,Xq); creates 2-by-2 matrices of interpolated function values, one matrix for each of the 3 functions. Vq will be of size 2-by-2-by-3. Class support for inputs X, V, Xq, EXTRAPVAL: float: double, single See also INTERPFT, SPLINE, PCHIP, INTERP2, INTERP3, INTERPN, PPVAL, griddedInterpolant, scatteredInterpolant. Documentation for interp1 doc interp1 Other uses of interp1 codistributed/interp1 dlarray/interp1 gpuArray/interp1 datetime/interp1 duration/interp1
  댓글 수: 1
Felix Obite
Felix Obite 2022년 9월 22일
Many thanks, was helpful.

댓글을 달려면 로그인하십시오.


Voss
Voss 2022년 9월 19일
Like this?
x = 2:2:20;
y = [1.23 0.95 1.1 1.44 1.47 1.1 1.21 1.4 1.1 1.39]*1e4;
plot(x,y)
x_new = 2:0.2:20;
y_new = interp1(x,y,x_new,'cubic');
hold on
plot(x_new,y_new,'r')
  댓글 수: 2
Felix Obite
Felix Obite 2022년 9월 20일
Many thanks.
Voss
Voss 2022년 9월 22일
You're welcome! Any questions, let me know. Otherwise, please "Accept This Answer". Thanks!

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Smoothing에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by