How to window sliding on matrix column?

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

Sean de Wolski
Sean de Wolski 2012년 2월 8일
What do you want to do with the window once you have it?

댓글을 달려면 로그인하십시오.

답변 (4개)

Walter Roberson
Walter Roberson 2012년 2월 8일

0 개 추천

Use blkproc() if your MATLAB still has it.
Andrei Bobrov
Andrei Bobrov 2012년 2월 8일

0 개 추천

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

N K
N K 2012년 2월 8일
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 2012년 2월 8일
Bmatrix = cat(2,B{:})

댓글을 달려면 로그인하십시오.

N K
N K 2012년 2월 8일

0 개 추천

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

Andrei Bobrov
Andrei Bobrov 2012년 2월 8일
Division into separate variables-bad way, instead of individual variables window1,window2,... use B{1},B{2},...
N K
N K 2012년 2월 8일
Thanks for recommend.
So, after process by using B{loop}, I will get matrix(1X12).
And I want take this matrix(1X12) connect each together to get new matrix(nX12).
Could you mind to show me how to do it?
Best.
Andrei Bobrov
Andrei Bobrov 2012년 2월 8일
B-cell array that contains 6 matrices of size 3 to 3, what is the matrix of size 1 to 12?
N K
N K 2012년 2월 8일
Sorry for make confuse.
On example above, I give a example matrix data.
My real is matrix size n to 12 (n is depend on data).
I want to windowing by 3 and overlap by 1.
Than change matrix from windowing to size 1 to 12 and store them on new matrix.
So, could you show me how to connect 1to12 together to new make new matrix?
best.
Andrei Bobrov
Andrei Bobrov 2012년 2월 8일
i don't undestand. Please give example for martix with size of (eg) 5x12
N K
N K 2012년 2월 8일
I really Sorry. I miss about row and column.
So, I will explain what I am doing to make you understand easily.
First, my matrix data is "12xN" (example 12X10)
1 2 3 4 5 6 7 8 9 10 -row 1
1 2 3 4 5 6 7 8 9 10 -row 2
....
1 2 3 4 5 6 7 8 9 10 -row 12
Second, I will use window sliding to grouping 3 column-overlap 1 column.
|1 2 3 |2 3 4 |4 5 6 |5 6 7| ... -row1
|1 2 3 |2 3 4 |4 5 6 |5 6 7| ... -row2
|.... |... |... |... |...
|1 2 3 |2 3 4 |4 5 6 |5 6 7| ... -row12
Third, process on each group to 12x1
|x1 |y1 |z1 | ...
|x2 |y2 |z2 | ...
|... |... |...| ...
|x12 |y12 |z12| ...
Finally, connect them together.
|x1 y1 z1 ... |
|x2 y2 z2 ... |
|.... |
|x12 y12 z12 ...|
Andrei Bobrov
Andrei Bobrov 2012년 2월 8일
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,[]).'
Andrei Bobrov
Andrei Bobrov 2012년 2월 8일
see ADD in my answer
Andrei Bobrov
Andrei Bobrov 2012년 2월 8일
and see comment by Sean de Wolski
Andrei Bobrov
Andrei Bobrov 2012년 2월 8일
what is going on in the process of: | 1 2 3 | -> | x1 |(example) ?

댓글을 달려면 로그인하십시오.

Sukuchha
Sukuchha 2012년 2월 8일

0 개 추천

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

카테고리

도움말 센터File Exchange에서 Word games에 대해 자세히 알아보기

제품

태그

질문:

N K
2012년 2월 8일

편집:

2013년 10월 4일

Community Treasure Hunt

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

Start Hunting!

Translated by