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

조회 수: 10 (최근 30일)
Raza Ali
Raza Ali 2022년 1월 17일
답변: Image Analyst 2022년 1월 17일
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