Contradictory results in command window with variable class and ischar function?

3 ビュー (過去 30 日間)
debugging a script i wrote and came across this? How is this possible?
K>> class structure(8).timetotemp
ans =
'char'
K>> ischar(structure(8).timetotemp)
ans =
logical
0
  1 件のコメント
Stephen23
Stephen23 2022 年 11 月 4 日
"Contradictory results in command window with variable class and ischar function?"
No.
"How is this possible?"

サインインしてコメントする。

採用された回答

Bruno Luong
Bruno Luong 2022 年 11 月 3 日
class structure(8).timetotemp
is like
class('structure(8).timetotemp')
which return char.
The correct function syntax call is
class(structure(8).timetotemp)

その他の回答 (1 件)

Steven Lord
Steven Lord 2022 年 11 月 3 日
This code, class structure(8).timetotemp, is equivalent to:
class('structure(8).timetotemp')
ans = 'char'
If you had a variable array named structure whose 8th element had a property or field named timetotemp and you wanted to know the class of that property or field, use the function form of the class function call rather than the command form.
structure(8) = struct('timetotemp', datetime('today'))
structure = 1×8 struct array with fields:
timetotemp
class(structure(8).timetotemp)
ans = 'datetime'

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by