How to extract the values that I want in a cell array?

2 visualizaciones (últimos 30 días)
M G
M G el 11 de Nov. de 2011
Hey all,
If we have: a={'1,17951,1,0' ; '1,20345,1,0' ; '1,22950,1,0' ; '1,25360,1,0'};
and I want to exclude 1,...,1,0 which are the same in all and as a result have cell array b as b = {17951 ; 20345 ; 22950 ; 25360}; how can I do that?
Thank you so much for your hint in advance.
Mehdi :)

Respuesta aceptada

Andrei Bobrov
Andrei Bobrov el 11 de Nov. de 2011
b = regexp(a,'\d\d\d\d\d','match')
b = cat(1,b{:})

Más respuestas (2)

Wayne King
Wayne King el 11 de Nov. de 2011
How is this different than the answer I gave before?
a={1,17951,1,0 ; 1,20345,1,0 ; 1,22950,1,0 ; 1,25360,1,0};
b = cellfun(@(x) x(x>1),a,'uni',0);
b(cellfun(@isempty,b))=[];
  2 comentarios
Wayne King
Wayne King el 11 de Nov. de 2011
look at b that contains what you want
M G
M G el 11 de Nov. de 2011
No, this one is different. The previous one worked perfectly. I realized that my actual values are in |''| e.g. |'1,17951,1,0'|instead of |1,17951,1,0|.

Iniciar sesión para comentar.


Fangjun Jiang
Fangjun Jiang el 11 de Nov. de 2011
I would use the comma as a way to split them and the select the second column.
a={'1,17951,1,0' ; '1,20345,1,0' ; '1,22950,1,0' ; '1,25360,1,0'};
b=regexp(a,',','split');
c=cellfun(@(x) x{1,2},b,'uni',false);
d=str2double(c)
  1 comentario
Andrei Bobrov
Andrei Bobrov el 11 de Nov. de 2011
Hi Fangjun! Variant:
b = regexp(a,',','split');
b = sortrows(cat(1,b{:})')'
b = b(:,end)

Iniciar sesión para comentar.

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