Testing a cell array if it is a string

조회 수: 10 (최근 30일)
Jeffrey Beckstead
Jeffrey Beckstead 2022년 5월 19일
댓글: Jeffrey Beckstead 2022년 5월 20일
I want to test a cell array to see if its contents are a string.
The function iscellstr checks to see if the contents of the cell are a character vector, not a string. Bad naming of a function in my opinion.
I am trying to test the cell array element if it is a string for error checking prior to use. This would be similar to isnumeric.

채택된 답변

Fangjun Jiang
Fangjun Jiang 2022년 5월 19일
a={'abc', 123, 'xyz',0};
b=cellfun(@isstr,a)
b = 1×4 logical array
1 0 1 0
  댓글 수: 1
Jeffrey Beckstead
Jeffrey Beckstead 2022년 5월 20일
The example you used are character vectors ( single quotes ). The strings that are generated are double quotes. Your suggestion did allow me to figure out how to use the function isstring on the cell array elements.
a = {"abc", 123, 'xyz', 0};
b=cellfun(@isstring,a)
b =
1×4 logical array
1 0 0 0
Thank you

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Cell Arrays에 대해 자세히 알아보기

태그

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by