How to find occurrences of a vector of strings in a cell string.

1 回表示 (過去 30 日間)
Paul Fishback
Paul Fishback 2017 年 5 月 1 日
編集済み: Stephen23 2017 年 5 月 1 日
I have a cell string, named Channels, that lists 69 distinct EEG channels, A1, A2, ...
To find an occurrence of a particular channel, e.g. B8, I use something like
find(ismember(Channels,'B8'))
which returns the correct index value of 25.
Now suppose I have a vector of a few of the channels, e.g. X=['A1','A2','B8'] and I want to find which indices in the cell string Channels correspond to those in X. In other words is there an elegant way to return the index values 1, 2, and 25?

採用された回答

xi
xi 2017 年 5 月 1 日
cs=[{'A1'},{'A2'},{'A3'},{'B1'},{'B8'}];
X=[{'A1'},{'B8'}];
find(ismember(cs,X));
ans: 1 5
  2 件のコメント
Paul Fishback
Paul Fishback 2017 年 5 月 1 日
Perfect! Thanks!
Stephen23
Stephen23 2017 年 5 月 1 日
編集済み: Stephen23 2017 年 5 月 1 日
You can construct these arrays in a much simpler way than that:
cs = {'A1','A2','A3','B1','B8'};
X = {'A1','B8'};

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCell Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by