How can I find name in a matrix or an array?

13 visualizaciones (últimos 30 días)
M G
M G el 30 de Mayo de 2011
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

Respuesta aceptada

Oleg Komarov
Oleg Komarov el 30 de Mayo de 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.

Más respuestas (0)

Categorías

Más información sobre Matrices and Arrays en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by