find the position of a specific cell entry

7 ビュー (過去 30 日間)
Birgit
Birgit 2012 年 11 月 21 日
Hello!
I have a cell array that looks like this B = {'AFG'; 'ALB'; 'AGO';'USA'; 'GER'; 'AUS'}
Now I would like to find the position of 'USA' in the cell array, so that I have pos_us = 4 (just as an example).
Could somebody please help me? I tried the "find" command but somehow it doesn't work for me...(or I used it wrong)
Thanks a lot! Birgit
  1 件のコメント
Jan
Jan 2012 年 11 月 21 日
It is helpful, if you post the code you have created yet. It is easier and useful to fix the bug in the code, than to post new code.

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

採用された回答

Harshit
Harshit 2012 年 11 月 21 日
[truefalse, index] = ismember('USA', B)
  1 件のコメント
Birgit
Birgit 2012 年 11 月 21 日
thank you very much! worked perfectly! :-)

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

その他の回答 (1 件)

Jan
Jan 2012 年 11 月 21 日
Faster than ismember and it finds multiple occurrences also:
index = find(strcmp(B, 'USA'));
  1 件のコメント
Birgit
Birgit 2012 年 11 月 21 日
even better! :-)

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

カテゴリ

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

製品

Community Treasure Hunt

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

Start Hunting!

Translated by