# Find a number inside a matrix

조회 수: 49(최근 30일)
jean claude 2020년 10월 28일
편집: Jon 2020년 10월 30일
##### 댓글 수: 2표시숨기기 이전 댓글 수: 1
jean claude 2020년 10월 28일
exactly you're right ! basically it's a python question since i am not that good in python i tried to solve it by matlab first after that convert to python, what do you think ?

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

### 답변(1개)

Jon 2020년 10월 28일
There are probably more efficient ways to do this but one approach would be to utilize MATLAB's find function.
If your matrix were given by A you can find for example the locations of all of the 8's using
[mIdx,nIdx] = find(A == 8)
Note this returns a vector, mIdx of row indices and vector nIdx of column indices where the 8's are located.
You could then find all of the 2's using
[pIdx, qIdx] = find( A == 2)
you could then check for each pair indices whether they were adjacent (within 1 element of each other)
if so add it to the list and so on
##### 댓글 수: 2표시숨기기 이전 댓글 수: 1
Jon 2020년 10월 30일
3 days in your room is too long :)

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

### Community Treasure Hunt

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

Start Hunting!

Translated by