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 20x20 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

댓글 수: 1

Original question in case he deletes it like he's done with other posts:
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 20x20 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

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

 채택된 답변

Massimo Zanetti
Massimo Zanetti 2016년 9월 29일

3 개 추천

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.

댓글 수: 6

Matlabhelp
Matlabhelp 2016년 9월 29일
So what this has essentially done is found each value from 1-5 in my array and e and denoted them by 1 in each of their own 20x20 cells?
Matlabhelp
Matlabhelp 2016년 9월 29일
I would also like to ask that if it were possible for each cell to only store the numbers which show a certain pattern? Rather than storing each position of numbers. Or is there a way to reference these now newly stored cells and denote where a pattern is
Matlabhelp
Matlabhelp 2016년 9월 29일
I really appreciate the help and excuse my many many questions hahaha, but how do i use the bwconncomp function. As stated in my original post how would you use this function to find pattern that consists of 3 ones in a single row and use it to search that whole array
Matlabhelp
Matlabhelp 2016년 9월 29일
I'm unfamiliar with how to use this function. Would you be able to provide an example, it's easier for me to see what is what and what needs to be defined in order to use this function to my full advantage.
Matlabhelp
Matlabhelp 2016년 9월 29일
I've had a read through and some elements of the page itself confuse me.
Just to clarify, BW = my array?
How does the CC = bwconncomp factor into the function?
Sorry, wrong function. Better to use regionprops, asking for the area of the connected regions:
S = regionprops(C{1},'Area')
Inspect S to get more familiar.

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

추가 답변 (0개)

카테고리

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

질문:

2016년 9월 29일

댓글:

2020년 8월 25일

Community Treasure Hunt

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

Start Hunting!

Translated by