How do I identify each element in a cell array as a string or a number?
12 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Victoria Loh
am 16 Mai 2017
Beantwortet: KL
am 16 Mai 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 Kommentare
Akzeptierte Antwort
Weitere Antworten (1)
KL
am 16 Mai 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 Kommentare
Siehe auch
Kategorien
Mehr zu Characters and Strings finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!