How do I identify each element in a cell array as a string or a number?
12 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Victoria Loh
el 16 de Mayo de 2017
Respondida: KL
el 16 de Mayo de 2017
I have a cell array A = {2,8,10,'Good',15,3,21,'Morning',12,26,9,'Joe'}. I want to perform a function on each element depending on whether it is a string or a number. So far, I have tried ischar but it returns 0 for all elements.
0 comentarios
Respuesta aceptada
Más respuestas (1)
KL
el 16 de Mayo de 2017
A = {2,8,10,'Good',15,3,21,'Morning',12,26,9,'Joe'};
q = cellfun(@(x) isnumeric(x) && numel(x)==1, A);
numA = A(q)
charA = A(~q)
0 comentarios
Ver también
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!