Effacer les filtres
Effacer les filtres

How can i get the index of all matrix value

2 vues (au cours des 30 derniers jours)
Ideth Kara
Ideth Kara le 6 Déc 2020
hello!
i have a matrix A , i want to find the index of all value in the matrix not a specific value like shown in B
A=[7 9 10 12 14 B=[1 1 1 1 1
20 25 30 17 15 2 2 2 2 2
27 10 32 28 8 3 3 3 3 3
11 13 26 34 16] 4 4 4 4 4]
  3 commentaires
Ideth Kara
Ideth Kara le 6 Déc 2020
Résultats de traduction
from A i want to get B
dpb
dpb le 6 Déc 2020
And by what magic did you get B from A?

Connectez-vous pour commenter.

Réponse acceptée

Ameer Hamza
Ameer Hamza le 6 Déc 2020
Are you looking for something like this
A;
B = repmat((1:size(A,1)).', 1, size(A,2))
  2 commentaires
Ideth Kara
Ideth Kara le 6 Déc 2020
it works well, thank you so much
Ameer Hamza
Ameer Hamza le 6 Déc 2020
I am glad to be of help!

Connectez-vous pour commenter.

Plus de réponses (2)

KALYAN ACHARJYA
KALYAN ACHARJYA le 6 Déc 2020
[r,c]=size(A);
B=reshape(repelem(1:c,r),[r,c])'

Image Analyst
Image Analyst le 6 Déc 2020
The other answers only give you the row indexes, like you showed in your (badly named) "B" matrix. A coordinate has two values -- the row of the element and the column of the element. If you want the full coordinate (both row and column indexes) you can use meshgrid(). See below:
A=[ 7 9 10 12 14
20 25 30 17 15
27 10 32 28 8
11 13 26 34 16]
[columnIndexes, B] = meshgrid(1:columns, 1:rows)
You'll see the row indexes B as you wanted, but you'll also see the column indexes:
columnIndexes =
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
B =
1 1 1 1 1
2 2 2 2 2
3 3 3 3 3
4 4 4 4 4

Catégories

En savoir plus sur Matrix Indexing dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by