Borrar filtros
Borrar filtros

finding a string in a cell array

1 visualización (últimos 30 días)
wesso Dadoyan
wesso Dadoyan el 22 de Jun. de 2016
Comentada: Azzi Abdelmalek el 22 de Jun. de 2016
ids1='519448(EPS1MN)' '519448(EPS2MN)' '519448(EPS3MN)' '519448(EPS4MN)' '519448(EPS5MN)' '519448(LTMD)' '519448(P)' '519448(DPS)' '519448(EPS)'
I want to find the cell that has embedded in it EPS1MN ,....EPS5MN
writing the following codes:
x2a=find(~isempty(strfind(ids1,'EPS1MN'))); % select rows.
x2b=find(~isempty(strfind(ids1,'EPS2MN')));
x2c=find(~isempty(strfind(ids1,'EPS3MN')));
x2d=find(~isempty(strfind(ids1,'EPS4MN')));
x2e=find(~isempty(strfind(ids1,'EPS5MN')));
is returning a value of 1 for x2a...x2e which is obviously wrong since the answers should be 1,2,...5
I am wondering what went wrong?
  2 comentarios
Azzi Abdelmalek
Azzi Abdelmalek el 22 de Jun. de 2016
wesso commented
the two answers work well with EPS1...EPS5 but they fail to identify the cell when the cell is (P). (i.e I want the answer to identify cell '519448(P)' and gets an answer of 7. Any help with this?
Azzi Abdelmalek
Azzi Abdelmalek el 22 de Jun. de 2016
If we give you the solution with (P), you will ask again it's not working with (T) or another string!

Iniciar sesión para comentar.

Respuesta aceptada

Azzi Abdelmalek
Azzi Abdelmalek el 22 de Jun. de 2016
ids1={'519448(EPS1MN)'
'519448(EPS2MN)'
'519448(EPS3MN)'
'519448(EPS4MN)'
'519448(EPS5MN)'
'519448(LTMD)'
'519448(P)'
'519448(DPS)'
'519448(EPS)'}
out=find(~cellfun(@isempty,regexp(ids1,'EPS[12345]MN')))

Más respuestas (1)

Thorsten
Thorsten el 22 de Jun. de 2016
out = find(cell2mat(regexp(ids1, 'EPS[1-5]MN')))

Categorías

Más información sobre Characters and Strings en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by