Sliding window: array gets smaller

2 ビュー (過去 30 日間)
Milena
Milena 2022 年 10 月 28 日
コメント済み: Rik 2022 年 11 月 1 日
I am currently working on implementing a sliding window into my code. This is is what i have got so far:
windowLength = 10;
for i = 1:length(green)-windowLength
greenDC(i) = mean(green(i:i+windowLength-1));
redDC(i) = mean(red(i:i+windowLength-1));
greenAC(i) = std(green(i:i+windowLength-1));
redAC(i) = std(red(i:i+windowLength-1));
%other codes
end
My problem is now, that i want to plot my results i get later in the code over the time axis t. But after my sliding window the arrays get smaller by 10 and now my time array is to big for the plotting to work.
Does anybody know how to solve this problem? Or is my sliding window completly wrong?
I already tried to interpolate the time, but its not working.
thanks in advance!
  7 件のコメント
Milena
Milena 2022 年 11 月 1 日
The error I calculated got bigger with movmean than without
Rik
Rik 2022 年 11 月 1 日
And how did you determine that this was due to an incorrect implementation and not inherent to your data?

サインインしてコメントする。

回答 (1 件)

Image Analyst
Image Analyst 2022 年 10 月 28 日
If you want to shrink the window, try this (untested)
windowLength = 10;
for i = 1:length(green)
index2 = min([length(green), i + windowLength - 1]);
greenDC(i) = mean(green(i:index2));
redDC(i) = mean(red(i:index2));
greenAC(i) = std(green(i:index2));
redAC(i) = std(red(i:index2));
%other codes
end
You know, imfilter has edge effect options, including shrinking window as it approached the edge of the signal or image.
  3 件のコメント
Image Analyst
Image Analyst 2022 年 10 月 28 日
@DGM, you're right.
Rik
Rik 2022 年 10 月 29 日
編集済み: Rik 2022 年 10 月 30 日
I believe the default behavior of this or a related function changed around R2017b. When I get home I will look up what function exactly and what the change was.
Edit: turns out it was R2017a, where imclose pads the image by half the size of the SE.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangePerformance and Memory についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by