How can I find name in a matrix or an array?
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Hey Matlab users, Suppose we have an array:
{channel_name.labels}
which refers to:
ans =
Columns 1 through 14
'Fp1' 'Fp2' 'F3' 'F4' 'C3' 'C4' 'P3' 'P4' 'O1' 'O2' 'F7' 'F8' 'T7' 'T8'
Suppose the array is much bigger than this and finding a particular name is really time consuming. I used 'Find' command but maybe I cannot use it properly and it didn't work. How can I find athe row and column of a particular name let's say 'P4'?
I thank you very much in advance :)
Mehdi
0 Commenti
Risposta accettata
Oleg Komarov
il 30 Mag 2011
c = {'Fp1','Fp2','F3','F4','C3','C4','P3'
'P4' ,'O1' ,'O2','F7','F8','T7','T8'};
idx = strcmpi('O1',c);
where idx is a logical array (same dim as c) that is true (1) where 'O1' is found in c.
To get the row and the column with find:
[r,c] = find(idx);
If you need r and c to retrieve O1 or to use them on an array the same dimension as c then I suggest to use idx. It is preferred in terms of performance to use logical indexes and to avoid calling find.
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Logical 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!