how to find patterns in an array
Show older comments
Hello
I have a 19*19 array filled with either a 1, -1 or a 0.
I need to find patterns of 5 repeating values next to each other of any value in both row and columns, and then store where the patterns are in an array.
example:
[1 0 0 0 0 0 1 0 -1 ]
and then store where the patterns are in another 19*19 array. As either a row pattern, column pattern or both.
any suggestions on how to do it? I'm completely lost.
1 Comment
per isakson
on 3 Oct 2014
Edited: per isakson
on 3 Oct 2014
Accepted Answer
More Answers (2)
Andrei Bobrov
on 3 Oct 2014
n = 5;
idxv = find(conv2(double(diff(A) == 0),ones(n-1,1),'same') == n-1);
idxv = idxv - 1;
idxh = find(conv2(double(diff(A,1,2) == 0),ones(1,n-1),'same') == n-1);
idxh = idxh - size(A,1);
Riley
on 3 Oct 2014
0 votes
Categories
Find more on Multidimensional Arrays in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!