Create (class object) variable from string: Matlab

Viewed 504

Say there is a cell array

A = {'objA', 'objB', 'objC'}

I want to have its members as instances of MyClass (see below) in Matlab. I couldn't get genvarname or eval to work for this.

Essentially I want loop through the array of names, A, and create a MyClass object for each member. This should result in the objects objA, objB and objC.

classdef MyClass
    properties
       something
       name
    end    
    methods
        function object = MyClass(name)
             object.name  = name;
        end
    end
end
1 Answers
Related