Single line string find

조회 수: 3 (최근 30일)
Chmical
Chmical 2012년 3월 27일
Is there a single line of code that would find a string in a cell array and output the column number? I have a large cell array of data with headers. I would like to be able to find a string but have the output give me the location (i.e. column number) of the found string. For example:
data = {'bab' 'bob' 'hey'}; test = 'bob'; Need the output to be 2 (bob is in the second column of the 1x3 data variable.
I can find bob and return [] [1] [] but not sure how to just get the column number without running a loop which takes time. I think there is probably a simple solution but I can't seem to visualize it.

채택된 답변

Matt Tearle
Matt Tearle 2012년 3월 27일
find(strcmp(test,data))
  댓글 수: 1
Chmical
Chmical 2012년 3월 27일
works like a dream. Thank you. Knew it should be something simple...

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by