Borrar filtros
Borrar filtros

How can i get the index of all matrix value

2 visualizaciones (últimos 30 días)
Ideth Kara
Ideth Kara el 6 de Dic. de 2020
Respondida: Image Analyst el 6 de Dic. de 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 comentarios
Ideth Kara
Ideth Kara el 6 de Dic. de 2020
Résultats de traduction
from A i want to get B
dpb
dpb el 6 de Dic. de 2020
And by what magic did you get B from A?

Iniciar sesión para comentar.

Respuesta aceptada

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

Iniciar sesión para comentar.

Más respuestas (2)

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

Image Analyst
Image Analyst el 6 de Dic. de 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

Categorías

Más información sobre Matrix Indexing en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by