フィルターのクリア

Extract specific values and row coloumn information in matrix

2 ビュー (過去 30 日間)
Fadhurrahman
Fadhurrahman 2022 年 1 月 31 日
コメント済み: Star Strider 2022 年 1 月 31 日
i have a matrix with size of 270x560 and has a value from 0 to 7 in it.
i want to extract a values of 5 in this matrix and also an information about the location (row and column) of these value in 270x560 matrix
is there any reference to do it?
here is some code that i already tried
x = B(:,:) ;
y = B(:,:) ;
z = x(y==5)
also i tried using find function but the result shows some random numbers
out = find(B == 5);

採用された回答

Cris LaPierre
Cris LaPierre 2022 年 1 月 31 日
Use this syntax: [row,col] = find(___)
[row,col] = find(B == 5);

その他の回答 (1 件)

Star Strider
Star Strider 2022 年 1 月 31 日
Try this —
M = randi([0 7], 5, 6) % Example Matrix
M = 5×6
7 1 7 5 5 7 1 6 1 2 2 4 5 1 6 3 6 1 2 7 4 2 5 0 2 2 5 1 6 7
[r,c] = find(M == 5); % r = Row, c = Column, For Each Occurrence
r = 5×1
3 5 1 1 4
c = 5×1
1 3 4 5 5
row_col = [r c] % Matching Row, Column References
row_col = 5×2
3 1 5 3 1 4 1 5 4 5
.
  2 件のコメント
Fadhurrahman
Fadhurrahman 2022 年 1 月 31 日
@Star Strider thank you very much. i think i need the code on the last one you share. thats one really helped
Star Strider
Star Strider 2022 年 1 月 31 日
My pleasure!

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeMATLAB についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by