Elements in a matrix

4 views (last 30 days)
Maik Petersen
Maik Petersen on 4 Jan 2014
Answered: Maik Petersen on 4 Jan 2014
Hello,
When I have a certain matrix, is there a possibility to check whether some value is on more than one position in the matrix.
So for example the identity matrix 3-by-3, how can I check whether the value '1' is multiple times there in the matrix?
Thanks in advance.

Accepted Answer

Azzi Abdelmalek
Azzi Abdelmalek on 4 Jan 2014
Idx=find(A==1)

More Answers (2)

Walter Roberson
Walter Roberson on 4 Jan 2014
sum(TheMatrix(:) == TheValue) > 1
In the more general case where you want to know whether any value is repeated, see unique()

Maik Petersen
Maik Petersen on 4 Jan 2014
You guys are great, thanks!

Categories

Find more on Creating and Concatenating Matrices in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!