With ischar usage - I get two different answers
4 次查看(过去 30 天)
显示 更早的评论
Hello, I found out that ischar gives two different answers as follows:
ischar("a")
ans =
logical
0
While, with this format, it gives the oppositve answer. Why is that? Thanks
chr = 'a'
chr =
'a'
tf = ischar(chr)
tf =
logical
1
0 个评论
采纳的回答
更多回答(1 个)
Dyuman Joshi
2024-1-23
编辑:Dyuman Joshi
2024-1-23
"Why is that?"
Because a character array (char) and a string array (string) are different. They are both different data types for text data in MATLAB.
You can see the class of both the variables defined below in the output from whos (which can also be found via class) -
y1 = "a";
y2 = 'a';
whos
%y1 is a string array
isstring(y1)
%not char array
ischar(y1)
%y2 is a char array
ischar(y2)
%not a string array
isstring(y2)
For more information -
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Whos 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!