How to index a cell vector of strings?

1 次查看(过去 30 天)
I have a vector of cells, each one is 'x' or 'y'. How can I index them, similar to the "find" function? Thank you.
  4 个评论
Cary
Cary 2015-6-22
To be more clear...I need to group the 'x's together and the 'y's together, and have their associated rows indexed.
Azzi Abdelmalek
Azzi Abdelmalek 2015-6-22
suppose s={'x','a','x','y','b','b','c','y','y','x'}, what is the expected result?

请先登录,再进行评论。

采纳的回答

Azzi Abdelmalek
Azzi Abdelmalek 2015-6-22
s={'a','b','x','c','d','x'}
idx=find(ismember(s,'x'))
  2 个评论
Azzi Abdelmalek
Azzi Abdelmalek 2015-6-22
Maybe you need this
s={'x','a','x','y','b','b','c','y','y','x'}
idx=ismember(s,'x')
idy=ismember(s,'y')
outx=[s(idx)' num2cell(find(idx))']
outy=[s(idy)' num2cell(find(idy))']

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by