find function on specific row and column of an array.
Show older comments
Hi,
I used find function in order to find row location of an array cell. To illustrate in an example:
A=magic(10)
A =
92 99 1 8 15 67 74 51 58 40
98 80 7 14 16 73 55 57 64 41
4 81 88 20 22 54 56 63 70 47
85 87 19 21 3 60 62 69 71 28
86 93 25 2 9 61 68 75 52 34
17 24 76 83 90 42 49 26 33 65
23 5 82 89 91 48 30 32 39 66
79 6 13 95 97 29 31 38 45 72
10 12 94 96 78 35 37 44 46 53
11 18 100 77 84 36 43 50 27 59
find(A(4:5,4)==21)
ans =
1
What I wanted to get is in intersection of a row window and a specific column, I wanted to find a specific input's row location in the matrix. I expected to find the row number as 4, however I get 1. Find function thinks A(4:5,4) is a new array and gives locations accordingly.
Does anyone know how to get the true row location when I specify an mxn sub-matrix in a rxs matrix where r>m, s>n?
Thx,
JD
Accepted Answer
More Answers (1)
Image Analyst
on 29 Oct 2016
Just don't specify a sub-matrix. Why are you doing that? It just ruins it and doesn't give you what you want. Just do it like this:
A=magic(10)
[rows, columns] = find(A == 21)
4 Comments
Image Analyst
on 29 Oct 2016
John's "Answer" moved here:
It is due to a matrix like
A=
17 24 1 8 15
23 5 1 14 16
4 6 1 20 22
10 12 1 21 3
11 18 1 2 9
11 13 2 5 1
10 20 2 5 13
18 5 2 5 8
11 14 2 6 19
19 6 2 6 1
25 28 3 28 22
24 25 3 22 23
25 20 3 30 21
28 21 3 6 26
23 27 3 28 27
I want to find row number of
A(9,4)
if I know I should look for it at
A(:,3)==2 and A(:,4)
I've got to use a window of row on a specific column. I thought find() could do it.
Image Analyst
on 29 Oct 2016
I don't know why you're extracting the 3rd and 4th columns. If you want to get row 9 and column 4 and find all elements in A that match the value at (9,4) then just use find exactly as I said:
[rows, columns] = find(A == A(9,4))
rows and columns will be vectors with the row and column where A = 2. So you will find the (9,4) element plus lots of other places where A = 2.
Image Analyst
on 29 Oct 2016
So you want to do basically a template matching. You have a known submatrix and want to find its location inside a larger matrix. You can use normxcorr2() to do that. I attach a demo.
Categories
Find more on Matrices and Arrays 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!