Create variable from cell array based on strings

1 visualización (últimos 30 días)
Hillaryfor2016
Hillaryfor2016 el 2 de Abr. de 2015
Comentada: Hillaryfor2016 el 2 de Abr. de 2015
I have a cell array something like this...
if true
Var1=
'A' 6
'B' 7
'B' 7
'A' 8
'C' 10
'A' 9
'A' 3
end
I want to pull out the values into a new variable which correspond only to 'A'
I.e generate this variable
if true
Var2=
'A' 6
'A' 8
'A' 9
'A' 3
end

Respuesta aceptada

Mohammad Abouali
Mohammad Abouali el 2 de Abr. de 2015
Var1={'A',6; ...
'B',7; ...
'B',7; ...
'A',8; ...
'C',10; ...
'A',9; ...
'A',3};
Var2=Var1(strcmpi(Var1(:,1),'A'),:)
Var2 =
'A' [6]
'A' [8]
'A' [9]
'A' [3]

Más respuestas (1)

Thomas Koelen
Thomas Koelen el 2 de Abr. de 2015
Editada: Thomas Koelen el 2 de Abr. de 2015
I think this should work. I am on mobile though so I can't check it atm.
index=strcmp(var1(:,1),'A');
index=index(:,any(index));
var2=var1(index,:);
  1 comentario
Hillaryfor2016
Hillaryfor2016 el 2 de Abr. de 2015
Cheers, haven't tried it but thanks for the help! (The 1st answer worked fine!)

Iniciar sesión para comentar.

Categorías

Más información sobre Characters and Strings 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