Clear Filters
Clear Filters

How to index a cell vector of strings?

1 view (last 30 days)
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 Comments
Cary
Cary on 22 Jun 2015
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 on 22 Jun 2015
suppose s={'x','a','x','y','b','b','c','y','y','x'}, what is the expected result?

Sign in to comment.

Accepted Answer

Azzi Abdelmalek
Azzi Abdelmalek on 22 Jun 2015
s={'a','b','x','c','d','x'}
idx=find(ismember(s,'x'))
  2 Comments
Azzi Abdelmalek
Azzi Abdelmalek on 22 Jun 2015
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))']

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!