How to find the position of a row in an array

12 ビュー (過去 30 日間)
Cantor Set
Cantor Set 2020 年 2 月 15 日
コメント済み: Cantor Set 2020 年 2 月 15 日
If I have an array like this
R=[1 0 1 1 1;
1 1 0 1 0;
1 0 1 1 0;
0 1 0 1 1;
0 0 1 0 1];
I want to find the position of S in R.
S=[1 0 1 1 0];
Is there a function which takes S as an input and returns me its position in R which is the 3rd row

回答 (2 件)

JESUS DAVID ARIZA ROYETH
JESUS DAVID ARIZA ROYETH 2020 年 2 月 15 日
rows=find(all(R==S,2))

Stephen23
Stephen23 2020 年 2 月 15 日
>> [~,Y] = ismember(S,R,'rows')
Y = 3
  1 件のコメント
Cantor Set
Cantor Set 2020 年 2 月 15 日
but what if S exists in 2 different rows:
R=[1 1 1; 1 1 1; 2 2 2];
[~,Y] = ismember(S,R,'rows')
Y=1
can it be refiend so that it returns Y=[1 2] ?

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

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by