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 Kommentare

Azzi Abdelmalek
Azzi Abdelmalek am 22 Jun. 2015
This is not clear, you can illustrate with an example
Cary
Cary am 22 Jun. 2015
I imported a matrix from a csv file. The data is all numerical except for one column, which is x,y,x,y,x,y...etc. I need to index this column in the matrix, just like you would with "find" for a numerical vector.
Cary
Cary am 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 am 22 Jun. 2015
suppose s={'x','a','x','y','b','b','c','y','y','x'}, what is the expected result?

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

Azzi Abdelmalek
Azzi Abdelmalek am 22 Jun. 2015

0 Stimmen

s={'a','b','x','c','d','x'}
idx=find(ismember(s,'x'))

2 Kommentare

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 am 22 Jun. 2015
Thank you very much!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Matrices and Arrays finden Sie in Hilfe-Center und File Exchange

Tags

Gefragt:

am 22 Jun. 2015

Kommentiert:

am 22 Jun. 2015

Community Treasure Hunt

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

Start Hunting!

Translated by