How to see the type of a matlab variable

I am looking at a rather large and poorly written Matlab program. One of the things that makes the code harder to understand is variables that do not show their type. In the search, I only found explanations on how to do this when debugging the code (whos and class commands). I'm looking for a way to view the type information in the editor itself.

For example, in the following code, I would like to know the type of A and B:

classdef Data
   properties
   B;

   function obj = Data(A)
        obj.B = A.B;
   end

      

Or is it a type not defined until the function is called, and A could be any class with a parameter B?

+3


source to share


2 answers


As I mentioned in the comments, unfortunately I don't know how to do this in the IDE without going into the debugger because MATLAB is not statically typed. You can also trace through the function and see what is calling methods / functions / etc. in the question and the variables used.



Your final sentence is correct. Looking at your example purely in the eyes of the IDE, there A

could be any datatype, even one where dot notation is invalid (and thus throws an error). This allows the user to add input validation for functions that are not inline.

+2


source


Usually numeric variables are defined as double, you can ask if a variable is of a particular datatype or not, here are some ways to do it.



+1


source







All Articles