필터 지우기
필터 지우기

find the position of a specific cell entry

조회 수: 12 (최근 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'));

카테고리

Help CenterFile Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by