MATLAB Answers

Charms
0

location of logical matrix

Asked by Charms
on 22 Aug 2019
Latest activity Commented on by madhan ravi
on 22 Aug 2019
Hi I have a 10 x 2 logical matrix and I would need to find out the location of the rows which both columns are ones i.e 1 1.
May I know how I may write for this? Thank you!

  0 Comments

Sign in to comment.

2 Answers

Answer by madhan ravi
on 22 Aug 2019
Edited by madhan ravi
on 22 Aug 2019
 Accepted Answer

Since you have a logical matrix it’simply:
ix=all(matrix ,2); % logical indexing is efficient
Wanted=find(ix)

  6 Comments

madhan ravi
on 22 Aug 2019
Thank you , sir Walter.
>> matrix
matrix =
4×2 logical array
1 1
0 1
1 0
0 1
>> ix=all(matrix ,2)
ix =
4×1 logical array
1
0
0
0
>> Wanted = find(ix) % this is what you want
Wanted =
1
>> matrix(ix,:)
ans =
1×2 logical array
1 1
>>
Charms
on 22 Aug 2019
thank you madhan for being so clear with your answer :)
madhan ravi
on 22 Aug 2019
While learning always visualize with a simple and short example to understand what's going on.

Sign in to comment.


KSSV
Answer by KSSV
on 22 Aug 2019

Read about ismember
idx = round(rand(10,2)) ;
vec = [1 1] ;
[c,ia] = ismember(idx,vec,'rows') ;
iwant = find(c) ;
idx(c,:)
idx(iwant,:)

  0 Comments

Sign in to comment.