Sliding window: array gets smaller
이전 댓글 표시
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
KALYAN ACHARJYA
2022년 10월 28일
Have you checked imfilter() funtion to slide the window (effiecint way)?
Adam Danz
2022년 10월 28일
The number of elements in your smoothed array size should only differ by "windowLength". You can shorten the length of your time vector by the same number of units for plotting. Smoothed data at time t(n) represents data smoothed between the interval of t0(n) and t0(n)+windowLength-1.
Milena
2022년 10월 29일
Rik
2022년 10월 30일
What exactly do you mean? Were the values you got unexpected? Or did you run into errors?
Milena
2022년 11월 1일
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
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
Are you sure about that? AFAIK, imfilter() handles all its edge treatment by padding. There are options for how the padding is generated and the extent of the returned array, but I don't recall anything about kernel truncation options. Same goes for medfilt2(), stdfilt(), etc.
EDIT: maybe you mean movmean(), movmedian(), etc. Those have truncation options.
Image Analyst
2022년 10월 28일
@DGM, you're right.
카테고리
도움말 센터 및 File Exchange에서 Performance and Memory에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!