Searching matrix for a particular value and ploting it

7 views (last 30 days)
hi there. Say I have a matrix A = [1 2 3; 2 1 5; 6 7 5;8 2 1]. and i want to search for the value '1' in the matrix then plot it according to the row and column it occurs in.
ex: the x,y coordinates for plotting would be:
(1,1) ==> 1 for the row and 1 for the column (2,2) ==> 2 for the row and 2 for the column (0,0) ==> nothing because there is no 1 in this row (4,3) ==> 4 for the row and 3 for the column
any help would be appreciated. thnx in advance

Accepted Answer

Andrei Bobrov
Andrei Bobrov on 14 Dec 2012
Edited: Andrei Bobrov on 14 Dec 2012
A = [1 2 3; 2 1 5; 6 7 5;8 2 1];
[row,col] = find(A == 1);
or
[row,col] = find(abs(A - 1) < eps(100));
out = [row,col];

More Answers (0)

Categories

Find more on MATLAB 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!