Instantiate class from name in MATLAB

后端 未结 4 1967
一整个雨季
一整个雨季 2020-12-31 07:31

I\'m trying to list classes I created in some folder in my Matlab folder - using only their name (class name)

as an example, I have a class called \'SimpleString\' -

4条回答
  •  礼貌的吻别
    2020-12-31 08:24

    You can use eval to instantiate the class using just the class name.

    instance = eval('SimpleString');
    

    However, if you're simply iterating through all the m-files in a folder containing class definitions and grabbing the file names, you'll only be able to invoke the default constructor using this method.

提交回复
热议问题