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

8 visualizaciones (últimos 30 días)
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

Respuesta aceptada

Image Analyst
Image Analyst el 17 de En. de 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

Más respuestas (0)

Categorías

Más información sobre Matrices and Arrays en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by