Instantiate class from name in MATLAB

后端 未结 4 2088
一整个雨季
一整个雨季 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:15

    Use str2func to get a function handle to the constructor. You can then call it with whatever arguments are appropriate.

    >> m = str2func('containers.Map')
    m = 
        @containers.Map
    >> x = m({'foo', 'bar'}, {0, 1})
    x = 
      containers.Map handle
      Package: containers
    
      Properties:
            Count: 2
          KeyType: 'char'
        ValueType: 'double'
      Methods, Events, Superclasses
    

提交回复
热议问题