Convert Index values from "find" function into coordinates.
28 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hello! I am using the find function in my code. If I want to find where all the 2's are in a matrix, suppose, this function will spit out the indices of all the 2 values, but it does so in an interesting way:
a =
1 1 2 1
1 1 1 1
1 1 2 1
1 2 1 1
Now, if I implement the function, find(a==2), I get:
ans =
8
9
11
Notice how it counts down each row until it reaches a 2. I would like a coordinate instead; I would like a (row,column) coordinate. Any ideas on how I can do this using the find function?
Much appreciated! Sean
0 Kommentare
Antworten (1)
Jan
am 28 Jan. 2017
Bearbeitet: Jan
am 28 Jan. 2017
When you have a question concerning a specific command, reading the corresponding docs helps. See doc find :
[row, col] = find(a == 2)
:-)
5 Kommentare
Jos (10584)
am 23 Feb. 2018
And without specifying the number of dimensions:
[subI{1:ndims(A)}] = ind2sub(size(A), find(A==2))
Siehe auch
Kategorien
Mehr zu Matrices and Arrays finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!