Sliding window in a matrix

10 visualizzazioni (ultimi 30 giorni)
Diana il 10 Nov 2015
Commentato: Joseph Cheng il 12 Nov 2015
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 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

Risposte (1)

Joseph Cheng il 10 Nov 2015
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 CommentiMostra 2 commenti meno recentiNascondi 2 commenti meno recenti
Joseph Cheng il 12 Nov 2015
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 il 12 Nov 2015
so... i started you off. I did not know what your conditions are when the 500 sliding window started to leave the 6000 matrix.

Accedi per commentare.

Categorie

Scopri di più su Shifting and Sorting Matrices in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by