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

10 次查看(过去 30 天)
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

采纳的回答

Image Analyst
Image Analyst 2022-1-17
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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Matrices and Arrays 的更多信息

标签

产品

Community Treasure Hunt

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

Start Hunting!

Translated by