Is there a function that will test if the input is char OR string OR cellstr?

91 次查看(过去 30 天)
Given many MatLab functions can easily handle strings, cellstrings and char arrays in their stride, is there a function which allows me to test if my variable is any of these?
I am aware that a simple function would be
function output = isText(myVar)
output = isstring(myVar)||ischar(myVar)||iscellstr(myVar);
end
but I feel like there should already by a function for this which is highly optimised?
I am sorry if this has been asked before, but if it has, the keywords are so used that this question is nowhere to be seen.

回答(2 个)

madhan ravi
madhan ravi 2020-7-2
Yours is good.
  1 个评论
Nicholas Ayres
Nicholas Ayres 2020-7-2
Thanks. I was assuming that, given many MatLab functions can take any of those 3 input types in order to produce the same thing, that there would be some kind of underlying type that you could test for to catch all 3 in one statement.
I guess this must be what happens when you pass the MatLab functions the data. shrug
Thanks

请先登录,再进行评论。


Fangjun Jiang
Fangjun Jiang 2020-7-2
You've made that function. If you look at the "See also" section of "help iscellstr", you don't see any other related functions.

类别

Help CenterFile Exchange 中查找有关 Characters and Strings 的更多信息

产品


版本

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by