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

8 views (last 30 days)
debugging a script i wrote and came across this? How is this possible?
K>> class structure(8).timetotemp
ans =
K>> ischar(structure(8).timetotemp)
ans =

Accepted Answer

Bruno Luong
Bruno Luong on 3 Nov 2022
class structure(8).timetotemp
is like
which return char.
The correct function syntax call is

More Answers (1)

Steven Lord
Steven Lord on 3 Nov 2022
This code, class structure(8).timetotemp, is equivalent to:
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:
ans = 'datetime'


Find more on Structures in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!