フィルターのクリア

With ischar usage - I get two different answers

5 ビュー (過去 30 日間)
Sergio
Sergio 2024 年 1 月 23 日
編集済み: Dyuman Joshi 2024 年 1 月 23 日
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

採用された回答

Aquatris
Aquatris 2024 年 1 月 23 日
編集済み: Aquatris 2024 年 1 月 23 日
"a" is a string not a char. You use double quotes for strings single quote for char.
isstring("a")
ans = logical
1
ischar("a")
ans = logical
0
isstring('a')
ans = logical
0
ischar('a')
ans = logical
1

その他の回答 (1 件)

Dyuman Joshi
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
Name Size Bytes Class Attributes cmdout 1x33 66 char y1 1x1 150 string y2 1x1 2 char
%y1 is a string array
isstring(y1)
ans = logical
1
%not char array
ischar(y1)
ans = logical
0
%y2 is a char array
ischar(y2)
ans = logical
1
%not a string array
isstring(y2)
ans = logical
0
For more information -

カテゴリ

Help Center および File ExchangeData Type Conversion についてさらに検索

タグ

製品


リリース

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by