필터 지우기
필터 지우기

movmean and mean comparasion

조회 수: 4 (최근 30일)
Ilya K
Ilya K 2021년 2월 19일
답변: Steven Lord 2021년 2월 19일
Hi, shouldn't those two lines do the same ?
curve2 = mean(BW, 1) ;
curve = movmean(BW, 1, 1) ;
I get different values and it's wierd, the first is calculating the average of a 2d-matrix over the columns,
and the second is doing the same but using moving average , thus it is taking 1 element over each 'move' over the columnes, isn't it ?

답변 (1개)

Steven Lord
Steven Lord 2021년 2월 19일
Nope. Let's look at an example:
BW = magic(4)
BW = 4×4
16 2 3 13 5 11 10 8 9 7 6 12 4 14 15 1
curve2 = mean(BW, 1)
curve2 = 1×4
8.5000 8.5000 8.5000 8.5000
curve = movmean(BW, 1, 1)
curve = 4×4
16 2 3 13 5 11 10 8 9 7 6 12 4 14 15 1
The movmean call slides a window of length 1 (so the window covers just one element) down each column of BW and computes the mean of the contents of each window. The mean of the elements in each of those windows is just the element itself, so curve is the same as BW.
isequal(curve, BW)
ans = logical
1
Now if your window was large enough that the whole column fit in the window and discard any windows that include elements outside of the matrix:
curve3 = movmean(BW, height(BW), 1, 'Endpoints', 'discard')
curve3 = 1×4
8.5000 8.5000 8.5000 8.5000
isequal(curve3, curve2)
ans = logical
1

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by