Borrar filtros
Borrar filtros

How to index a cell vector of strings?

1 visualización (últimos 30 días)
Cary
Cary el 22 de Jun. de 2015
Comentada: Cary el 22 de Jun. de 2015
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 comentarios
Cary
Cary el 22 de Jun. de 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 el 22 de Jun. de 2015
suppose s={'x','a','x','y','b','b','c','y','y','x'}, what is the expected result?

Iniciar sesión para comentar.

Respuesta aceptada

Azzi Abdelmalek
Azzi Abdelmalek el 22 de Jun. de 2015
s={'a','b','x','c','d','x'}
idx=find(ismember(s,'x'))
  2 comentarios
Azzi Abdelmalek
Azzi Abdelmalek el 22 de Jun. de 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))']
Cary
Cary el 22 de Jun. de 2015
Thank you very much!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Matrix Indexing en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by