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

13 次查看(过去 30 天)
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

采纳的回答

Oleg Komarov
Oleg Komarov 2011-5-30
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.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Matrices and Arrays 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by