Create superclass objects in a for loop

조회 수: 2 (최근 30일)
Umit
Umit 2012년 2월 16일
편집: Jan 2013년 10월 15일
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.

채택된 답변

Umit
Umit 2012년 2월 17일
I restarted matlab, everything works fine, :D

추가 답변 (2개)

Umit
Umit 2012년 2월 17일
Noone knows how to initiate superclass in a for loop?
  댓글 수: 1
Walter Roberson
Walter Roberson 2012년 2월 17일
I am not no-one, and I don't know anything about the topic. Negating both sides we arrive at the logical conclusion that no-one knows anything about the topic.

댓글을 달려면 로그인하십시오.


Daniel Shub
Daniel Shub 2012년 2월 17일
Maybe I am missing something here, but doesn't it make more sense for the AlliedStates constructor to handle an array input.

카테고리

Help CenterFile Exchange에서 Linear Algebra에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by