Sliding window in a matrix
8 次查看(过去 30 天)
显示 更早的评论
Hello Guys, I have this code that runs through a matrix of (6000,3). My code runs each column and then each element in the column (rows). If the values of the column are bigger than the threshold it returns one and if they are smaller returns 0. But it is to sensitive for my data, I want to use a window that runs through 500 elements in the column and if half or more of them are bigger than the threshold give one to that entire window. How do I do this? So far its running each element at the time. This is the code:
for i=1:1:3; %runns trhough the matrix
SD=std(E(:,i))
thresh=SD
for ii=1:1:length(E(:,i)); %runs trhough every element
if E(ii,i) > thresh;
detect(ii,i)=1;
else
detect(ii,i)=0;
end
end
end
Thanks!
0 个评论
回答(1 个)
Joseph Cheng
2015-11-10
you can perform what you're doing a bit simpler.
E = randi(100,6000,3); %my generation of dummy data
windowL =500;
thresh= 50;
for ind = 1:length(E(:,1))-windowL+1 % set the end such that you don't index more than the length of the array E.
Window = E(ind:ind+windowL-1); %pulled out section of E to be used
tWindow = Window>thresh; % threshold the window you'll get a 500x3 logical array
stWindow = sum(tWindow); % then take the sum to count how many are over the threshold per column (you'll end up with a 1x3 matrix of how many are over the threshold.
tstwindow = stWindow>windowL/2; % then you can threshold again to see which ones have a majority over the threshold.
detect(ind,:) = ttwindow; %then set your detected array based on the last calculation.
end
I broke up the code a bit to show some intermediate steps showing how using logical operations you can perform these things.
4 个评论
Joseph Cheng
2015-11-12
so... i started you off. I did not know what your conditions are when the 500 sliding window started to leave the 6000 matrix.
Joseph Cheng
2015-11-12
so... i started you off. I did not know what your conditions are when the 500 sliding window started to leave the 6000 matrix.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrices and Arrays 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!