find index conditional on two vectors

조회 수: 1 (최근 30일)
MiauMiau
MiauMiau 2017년 6월 23일
댓글: MiauMiau 2017년 6월 23일
Hi,
I have two vectors =
resp = [1 2 3 1 1 2 3 3 3 1];
fing = [1 2 1 2 1 1 1 2 2 1];
How do I find the indices of resp where resp ==1 and fing ==1 (for instance in this example, this would be index 1 of resp, index 5 of resp, and index 10 of resp)?
Many thanks

채택된 답변

Adam
Adam 2017년 6월 23일
편집: Adam 2017년 6월 23일
find( resp == 1 & fing == 1 );
If you don't need the actual linear indices though then the logical vector returned by just
resp == 1 & fing == 1
will work as an index into other arrays if needed and is more efficient than finding the linear indices first.
  댓글 수: 1
MiauMiau
MiauMiau 2017년 6월 23일
oh my, so simple...I was trying find(resp(resp==1&fing==1)) which delivered indices of the subset. Many thanks

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

추가 답변 (1개)

KSSV
KSSV 2017년 6월 23일
clc; clear all ;
resp = [1 2 3 1 1 2 3 3 3 1];
fing = [1 2 1 2 1 1 1 2 2 1];
idx1 = find(resp==1)
idx2 = find(resp==2)
  댓글 수: 1
MiauMiau
MiauMiau 2017년 6월 23일
?? That is not answering my question at all. Where are you making use of "fing" in your example..?

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

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by