Find cases of vectors-patterns in an array
5 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
I have 4 cases of vectors inside an array that I want to index. All of them have trailing -1. I would like to index such patterns in my array.
Case 1
0 -1 -1 -1...-1 0 % starts with 0 ends with 0
Case 2
0 -1 -1 -1...-1 1 % starts with 0 ends with 1
Case 3
1 -1 -1 -1...-1 1 % starts with 1 ends with 1
Case 4
1 -1 -1 -1...-1 0 % starts with 1 ends with 0
An example of an array could be:
t=[0 0 0 0 0 *0 -1 1* 1 1 1 1 *1 -1 -1 -1 1* 0 0 0 0];
In this array case 2 and case 3 are observed in between the asterisks.
Thank you!
0 Commenti
Risposta accettata
Andrei Bobrov
il 17 Ago 2013
Modificato: Andrei Bobrov
il 17 Ago 2013
t=[0 0 0 0 0 0 -1 1 1 1 1 1 1 -1 -1 -1 1 0 0 0 0];
t1 = t(:).' == -1;
ii = [strfind(t1,[0 1]);strfind(t1,[1 0])+1].';
cases = [0 0;0 1;1 1;1 0];
[i1,i1] = ismember(t(ii),cases,'rows');
out = [i1, ii];
Più risposte (1)
Giorgos Papakonstantinou
il 17 Ago 2013
Modificato: Giorgos Papakonstantinou
il 17 Ago 2013
0 Commenti
Vedere anche
Categorie
Scopri di più su Matrix Indexing in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!