Azzera filtri
Azzera filtri

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

4 visualizzazioni (ultimi 30 giorni)
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

Risposta accettata

Image Analyst
Image Analyst il 17 Gen 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

Più risposte (0)

Categorie

Scopri di più su Matrices and Arrays in Help Center e File Exchange

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by