MATLAB: Finding patterns in the array

assignment sheit

Hello
I'm trying to find a pattern within my matrix and then store and label that found pattern in a separate array. The code i have develop so far is as below, where roundData is my my 20×20 Matrix. The matrix consists of integers of 1-5 and Im trying to source from the whole array if a set of numbers such as all 1's form a block
1 1
1 1
Such as above. Once this pattern has been found it will store into another array showing that pattern has been found and denoted by anything else, eg an x or something. I'm wondering where in my code have i gone wrong and how do i store it in another array.
mapValue = 0;
mapValue1 = 0;
mapValue2 = 0;
mapValue3 = 0;
for r = 1:MAX_ROWS - 1
for c = 1:MAX_COLUMNS - 1
mapValue = roundData (r,c);
mapValue1 = roundData (r,c+1);
mapValue2 = roundData(r+1,c);
mapValue3 = roundData (r+1,c+1);
if mapValue == mapValue1 && mapValue == mapValue2 && mapValue == mapValue 3;
end
end
end

Best Answer

Assume A is you matrix with values from 1 to 5. You can map automatically the entries having the same value in this way:
C = cell(1,5);
for k=1:5
C{k} = (A==k);
end
Every C{k} is a logical matrix storing the positions of the numbers.