MATLAB Answers

How to get 'type' of a variable in matlab?

5,988 ビュー (過去 30 日間)
Andrew 2013 年 11 月 15 日
コメント済み: Steven Lord 2020 年 2 月 21 日
Hi, We declare many types of variables in matlab such as double, string, symbolic etc. How to get type of a variable?

  0 件のコメント



Sean de Wolski
Sean de Wolski 2013 年 11 月 15 日
編集済み: MathWorks Support Team 2018 年 11 月 27 日
To get the data type, or class, of a variable, use the “class” function.
x = 100;
To determine if a variable has a specified data type, use the “isa” function.
tf = isa(x,'double')
For a list of functions that determine if variables have specific attributes, see “is*”.
You also can use the “validateattributes” function, which can validate many classes at once easily.

  0 件のコメント


その他の回答 (1 件)

Azzi Abdelmalek
Azzi Abdelmalek 2013 年 11 月 15 日

  3 件のコメント

Robert Bruner
Robert Bruner 2019 年 7 月 17 日
"Error: the class function must be called from a class constructor"
how can I do this from the command-line in MATLAB?
Bill Tubbs
Bill Tubbs 2020 年 2 月 20 日
I have the same problem.
>> class(theFiles)
ans =
>> class(
Error using class
The CLASS function must be called from a class constructor.
Steven Lord
Steven Lord 2020 年 2 月 21 日
I'm guessing theFiles is a non-scalar struct array, which would mean that is a comma-separated list. This makes MATLAB think you're using a different syntax for the class function, one associated with the older style of classes. See the "Obsolete Class Definition Syntax" section on the class documentation page.
You could try:
% etc


Community Treasure Hunt

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

Start Hunting!

Translated by