Filter löschen
Filter löschen

How can i get the index of all matrix value

2 Ansichten (letzte 30 Tage)
Ideth Kara
Ideth Kara am 6 Dez. 2020
Beantwortet: Image Analyst am 6 Dez. 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 Kommentare
Ideth Kara
Ideth Kara am 6 Dez. 2020
Résultats de traduction
from A i want to get B
dpb
dpb am 6 Dez. 2020
And by what magic did you get B from A?

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

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

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (2)

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

Image Analyst
Image Analyst am 6 Dez. 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

Kategorien

Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by