Find the index of a string is structure

3 次查看(过去 30 天)
How can you find the index of the cell with the word dranken in a strucurearray with the fields data and textdata? I know that the word always is goind to be in the field textdata.
Thank you

采纳的回答

Sergey Kasyanov
Sergey Kasyanov 2018-4-6
编辑:Sergey Kasyanov 2018-4-6
As i understand you right, the field textdata contains cell array with some strings. Let figure that A - structure. Then if you looking for exact coincidence try this:
NumberOfCell=find(cellfun(@strcmp,A.textdata,repmat({'word'},size(A.textdata)))==1)
If textdata contain strings where you want find one word then try this:
NumberOfCell=cell2mat(cellfun(@strfind,A.textdata,repmat({'word'},size(A.textdata)),'UniformOutput',false))
  1 个评论
Sergey Kasyanov
Sergey Kasyanov 2018-4-6
编辑:Sergey Kasyanov 2018-4-6
Sorry. There is mistype.
NumberOfCell=find(cellfun(@strcmp,A.textdata,repmat({'word'},size(A.textdata)))==1)

请先登录,再进行评论。

更多回答(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