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
댓글 수: 0
채택된 답변
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 Center 및 File Exchange에서 Matrices and Arrays에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!