How do I identify each element in a cell array as a string or a number?

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.

 채택된 답변

추가 답변 (1개)

KL
KL 2017년 5월 16일
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)

카테고리

도움말 센터File Exchange에서 Characters and Strings에 대해 자세히 알아보기

질문:

2017년 5월 16일

답변:

KL
2017년 5월 16일

Community Treasure Hunt

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

Start Hunting!

Translated by