Azzera filtri
Azzera filtri

How can i get the index of all matrix value

2 visualizzazioni (ultimi 30 giorni)
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 Commenti
Ideth Kara
Ideth Kara il 6 Dic 2020
Résultats de traduction
from A i want to get B
dpb
dpb il 6 Dic 2020
And by what magic did you get B from A?

Accedi per commentare.

Risposta accettata

Ameer Hamza
Ameer Hamza il 6 Dic 2020
Are you looking for something like this
A;
B = repmat((1:size(A,1)).', 1, size(A,2))

Più risposte (2)

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

Image Analyst
Image Analyst il 6 Dic 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

Community Treasure Hunt

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

Start Hunting!

Translated by