Borrar filtros
Borrar filtros

How to window sliding on matrix column?

1 visualización (últimos 30 días)
N K
N K el 8 de Feb. de 2012
Editada: Ronaldo el 4 de Oct. de 2013
Sorry for my weak English.
Dear all. I'am new in MATLAB, so I need your help.
I have some problem about how to write code for window sliding.
I have some matrix for example
1 2 3 4 5 6 7 8
9 1 2 3 4 5 6 7
8 9 1 2 3 4 5 6
So, I want to get group by window sliding like
(example. window size is 3 and overlap by 1 column)
group1 group2 group3 group4 .....
1 2 3 2 3 4 3 4 5 4 5 6 .....
9 1 2 1 2 3 2 3 4 3 4 5 .....
8 9 1 9 1 2 1 2 3 2 3 4 .....
Could you mind if I want you to show the code for solve this problem?
Best.
  1 comentario
Sean de Wolski
Sean de Wolski el 8 de Feb. de 2012
What do you want to do with the window once you have it?

Iniciar sesión para comentar.

Respuestas (4)

Walter Roberson
Walter Roberson el 8 de Feb. de 2012
Use blkproc() if your MATLAB still has it.

Andrei Bobrov
Andrei Bobrov el 8 de Feb. de 2012
eg:
EDIT
A= [1 2 3 4 5 6 7 8
9 1 2 3 4 5 6 7
8 9 1 2 3 4 5 6]
m = 3;
h = hankel(1:m,m:size(A,2))
B = arrayfun(@(i1)A(:,h(:,i1)),1:size(h,2),'un',0)
group = cat(3,B{:})
Bmatrix = cat(2,B{:})
ADD
A - your matrix(12x10)
m = 3;
[a,b] = size(A);
At = A.';
out = reshape(At(bsxfun(@plus,hankel(1:m,m:b),...
permute(0:b:b*(a-1),[1 3 2]))),(b-m+1)*m,[]).'
ADD2
m = 3;
n = size(A,2) - m +1;
out = zeros(size(A,1),m*n);
k = 2:-1:0;
for i1 = 1:n
out(:,i1*m - k) = A(:,i1:i1+m-1);
end
ADD3
for example, your process is the summation
A= [1 2 3 4 5 6 7 8
9 1 2 3 4 5 6 7
8 9 1 2 3 4 5 6]
m = 3;
h = hankel(1:m,m:size(A,2))
B = arrayfun(@(i1)sum(A(:,h(:,i1)),2),1:size(h,2),'un',0)
Bmatrix = cat(2,B{:})
or
B = colfilt(A,[1 3],'sliding',@sum)
out = B(:,2:end-1)
  2 comentarios
N K
N K el 8 de Feb. de 2012
Could you mind to explain code in ADD and why use reshape?
Now, I have each column already (I have my process to transform matrix to 12x1).
But I don't know how to merge them together to create new matrix.
best.
Andrei Bobrov
Andrei Bobrov el 8 de Feb. de 2012
Bmatrix = cat(2,B{:})

Iniciar sesión para comentar.


N K
N K el 8 de Feb. de 2012
Thanks for answer.
Than I have other problems now.
from
m = 3;
h = hankel(1:m,m:size(A,2))
B = arrayfun(@(i1)A(:,h(:,i1)),1:size(h,2),'un',0)
group = cat(3,B{:})
data will be in group. Than, I try to get data in each group to each variable
by create new variable in for loop like
[Bw,Bl]=size(B);
for loop = 1:1:Bl
window(loop) = B{1,loop};
end
But system doesn't let me do it. I want data in full matrix in each window.
How does to store each matrix in each variable ?
Best.
  10 comentarios
Andrei Bobrov
Andrei Bobrov el 8 de Feb. de 2012
and see comment by Sean de Wolski
Andrei Bobrov
Andrei Bobrov el 8 de Feb. de 2012
what is going on in the process of: | 1 2 3 | -> | x1 |(example) ?

Iniciar sesión para comentar.


Sukuchha
Sukuchha el 8 de Feb. de 2012
use function nlfilter which is similar to blockproc which operates in a block but unlike blockproc its a sliding block window.
for mor info, doc nlfilter

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by