Testing a cell array if it is a string

15 Ansichten (letzte 30 Tage)
Jeffrey Beckstead
Jeffrey Beckstead am 19 Mai 2022
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.

Akzeptierte Antwort

Fangjun Jiang
Fangjun Jiang am 19 Mai 2022
a={'abc', 123, 'xyz',0};
b=cellfun(@isstr,a)
b = 1×4 logical array
1 0 1 0
  1 Kommentar
Jeffrey Beckstead
Jeffrey Beckstead am 20 Mai 2022
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

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Cell Arrays finden Sie in Help Center und File Exchange

Tags

Produkte


Version

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by