Filter löschen
Filter löschen

find index conditional on two vectors

1 Ansicht (letzte 30 Tage)
MiauMiau
MiauMiau am 23 Jun. 2017
Kommentiert: MiauMiau am 23 Jun. 2017
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

Akzeptierte Antwort

Adam
Adam am 23 Jun. 2017
Bearbeitet: Adam am 23 Jun. 2017
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 Kommentar
MiauMiau
MiauMiau am 23 Jun. 2017
oh my, so simple...I was trying find(resp(resp==1&fing==1)) which delivered indices of the subset. Many thanks

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

KSSV
KSSV am 23 Jun. 2017
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 Kommentar
MiauMiau
MiauMiau am 23 Jun. 2017
?? That is not answering my question at all. Where are you making use of "fing" in your example..?

Melden Sie sich an, um zu kommentieren.

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by