Looking for an efficient way of finding elements in a cell array of character vectors

2 ビュー (過去 30 日間)
I have a cell array of character vectors, named "Channels", in which each entry corresponds a particular EEG channel label. I'd like to find indices that correspond to all P channels. For a single channel, P3, I have no problem. For example,
index = find(strcmp(Channels, 'P3'))
returns the correct index.
To find those indices that correspond to all four P labels, P3, P4, P7, P8, I can "glue" things together, such as
index = find(strcmp(Channels, 'P3')|strcmp(Channels,'P4')|strcmp(Channels,'P7')|strcmp(Channels,'P8'))
Of course, there has to be a more efficient way. I can't seem to find the correct manner to combine 'P3', 'P4', 'P7','P8' so so as to do it one step.

採用された回答

Stephen23
Stephen23 2019 年 2 月 21 日
編集済み: Stephen23 2019 年 2 月 21 日
ismember(Channels,{'P3','P4','P7','P8'})

その他の回答 (1 件)

Paul Fishback
Paul Fishback 2019 年 2 月 21 日
編集済み: Paul Fishback 2019 年 2 月 21 日
Thanks very much. The ismember will return a logical array. If I tack on the find command, I get the desired indices as well:
find(ismember(Channels,{'P3','P4','P7','P8'}))

カテゴリ

Help Center および File ExchangeDescriptive Statistics についてさらに検索

製品


リリース

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by