One way to calculate the moving minimum of a vector in Matlab is to use the filter
function with a vector of ones as the filter coefficients. Here is an example code snippet:
main.m106 chars4 lines
In the above code, v
is the input vector, w
is the window size, and movmin_v
is the resulting vector of moving minimums. The filter
function applies a moving average with a window size of w
to the input vector v
, which effectively calculates the moving minimum. The []
argument is used for padding the input vector to ensure the output is the same size as the input. The 2
argument specifies that the filter operates along the second dimension of the input vector, which is the row dimension in this example.
gistlibby LogSnag