MATLAB: Create superclass objects in a for loop

classconstructorsuperclass

classdef SimulationAlgorithm < AgentAlgorithm
%Paremeters that can only set by constructor
properties(GetAccess = 'public', SetAccess = 'immutable')
NbofAlliedAgents;
NbofEnemyAgents;
TotalSimTime;
end
methods
%Constructor for Simulation Algorithm
function Sim = SimulationAlgorithm(N, M, T)
Sim.NbofAlliedAgents = N;
Sim.NbofEnemyAgents = M;
Sim.TotalSimTime = T;
%Creates Agents via AlliedAgent SuperClass
AlliedStates = Sim.CreateRandomStates(Sim, ...
Sim.NbofAlliedAgents, 'Allied');
EnemyStates = Sim.CreateRandomStates(Sim,...
Sim.NbofEnemyAgents, 'Enemy');
for i=1:Sim.NbofAlliedAgents
AlliedAgents(i) = AlliedAgents(i)@AgentAlgorithm(AlliedStates(i,:));
end
end
end
%These methods can be invoked w/o an object initalized, Obj needs to
%be send as parameter as a result
methods (Static, Access = 'private')
%Creates [x y z Vx Vy Vz] vector for all NbofAgents. Distinguishes
%Allied vs Enemy agents via Type parameter.
function [Vector] = CreateRandomStates(Obj, NbofAgents, Type)
%SIMPLIFIED VERSION NOT REAL ONE
Vector = randi([1 100], [NbofAgents 6]);
end
end
end
How can I call superclass constructor in a for loop. The nb. of the objects of AgentAlgorithm varies. In current state, it always says superclass constructor should be top state.

Best Answer

I restarted matlab, everything works fine, :D