How can i get the index of all matrix value
Mostra commenti meno recenti
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
KSSV
il 6 Dic 2020
What is the output you expect given A and B?
Ideth Kara
il 6 Dic 2020
dpb
il 6 Dic 2020
And by what magic did you get B from A?
Risposta accettata
Più risposte (2)
KALYAN ACHARJYA
il 6 Dic 2020
[r,c]=size(A);
B=reshape(repelem(1:c,r),[r,c])'
1 Commento
Image Analyst
il 6 Dic 2020
Try again.
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
Categorie
Scopri di più su Creating and Concatenating Matrices in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!