How to save the location of particular element of a MATRIX?

11 views (last 30 days)
I have a 10 x 10 matrix
A = [ 0 1 2 3 4 5 6 7 8 9;
1 2 3 4 5 6 7 8 9 0;
2 3 3 5 6 7 8 9 0 1;
3 3 3 6 7 8 9 0 1 3;
3 3 3 7 8 9 3 3 3 3;
3 6 7 3 9 0 3 3 3 3;
3 7 8 3 0 1 3 3 3 3;
7 8 9 3 1 3 3 4 5 3;
8 9 0 1 3 3 4 5 6 7;
9 0 1 2 3 4 5 6 7 8];
I need to save the location of element 3 in each column in a new matrix

Accepted Answer

Image Analyst
Image Analyst on 17 Jan 2022
To get the row and column of each location the 3 appears in the matrix, use find()
A = [ 0 1 2 3 4 5 6 7 8 9;
1 2 3 4 5 6 7 8 9 0;
2 3 3 5 6 7 8 9 0 1;
3 3 3 6 7 8 9 0 1 3;
3 3 3 7 8 9 3 3 3 3;
3 6 7 3 9 0 3 3 3 3;
3 7 8 3 0 1 3 3 3 3;
7 8 9 3 1 3 3 4 5 3;
8 9 0 1 3 3 4 5 6 7;
9 0 1 2 3 4 5 6 7 8];
[rows, columns] = find(A == 3)
rows = 34×1
4 5 6 7 3 4 5 2 3 4
columns = 34×1
1 1 1 1 2 2 2 3 3 3

More Answers (0)

Categories

Find more on Matrices and Arrays in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!