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

16 views (last 30 days)
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

Accepted Answer

Oleg Komarov
Oleg Komarov on 30 May 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.

More Answers (0)

Categories

Find more on Matrices and Arrays in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!