How to smooth data in MatLab? - smoothdata -- MatLab

 How to smooth data in MatLab? - smoothdata -- MatLab

How to smooth data in MatLab?

[Ans]
smoothdata

[description]

<B> = smoothdata(<A>) 

It will return a moving average of the elements of a vector using a fixed window length that is determined heuristically. The window slides down the length of the vector, computing an average over the elements within each window.

  • If A is a matrix, then smoothdata computes the moving average down each column.

  • If A is a multidimensional array, then smoothdata operates along the first dimension whose size does not equal 1.

  • If A is a table or timetable with numeric variables, then smoothdata operates on each variable separately.

<B> = smoothdata(<A>,<dim>) 
It will operate along the dimension dim of A. For example, if A is a matrix, then smoothdata(A,2) smooths the data in each row of A.


<B> = smoothdata(___,<method>) 
It will specify the smoothing method for either of the previous syntaxes. For example, B = smoothdata(A,'sgolay') uses a Savitzky-Golay filter to smooth the data in A.

<B> = smoothdata(___,<method>,<window>) 
It will specify the length of the window used by the smoothing method. For example, smoothdata(A,'movmedian',5) smooths the data in A by taking the median over a five-element sliding window.

<B> = smoothdata(___,<nanflag>) 
It will specify how NaN values are treated for any of the previous syntaxes. 'omitnan' ignores NaN values and 'includenan' includes them when computing within each window.

<B = smoothdata(___,<Name>,<Value>) 
It will specify additional parameters for smoothing using one or more name-value pair arguments. For example, if t is a vector of time values, then smoothdata(A,'SamplePoints',t) smooths the data in A relative to the times in t.

[<B>,<windows>] = smoothdata(___)
It  also will return the moving window length.



more details on:

code
clear
clc
%smoothdata example1
N=20;
x = 1:N;
A = cos(2*pi*0.05*x+2*pi*rand) + 0.5*randn(1,N)
B = smoothdata(A)
plot(x,A,'-o',x,B,'-x')
legend('Original Data','Smoothed Data')




Comments