필터 지우기
필터 지우기

How can i get the index of all matrix value

조회 수: 2 (최근 30일)
Ideth Kara
Ideth Kara 2020년 12월 6일
답변: Image Analyst 2020년 12월 6일
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
Ideth Kara
Ideth Kara 2020년 12월 6일
Résultats de traduction
from A i want to get B
dpb
dpb 2020년 12월 6일
And by what magic did you get B from A?

댓글을 달려면 로그인하십시오.

채택된 답변

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

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

KALYAN ACHARJYA
KALYAN ACHARJYA 2020년 12월 6일
[r,c]=size(A);
B=reshape(repelem(1:c,r),[r,c])'

Image Analyst
Image Analyst 2020년 12월 6일
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

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by