Instantiating Object Arrays with superclass call

Hi, I've wrote a baseStation class matlab class, which constructor is given as following:
function obj = baseStation(btscoord,btsid,attachedcell,aa,tx,sirmin,rxmax,rxmin,txmax,txmin)
nargin
if nargin <3
aa=0;
tx=0;
sirmin=0;
rxmax=0;
rxmin=0;txmax=0;txmin=0;
end
%call the superconstructor
obj = obj@btsRadio(aa,tx,sirmin,rxmax,rxmin,txmax,txmin);
%initiate class variable
obj.btsID = btsid;
obj.btsCoord = btscoord;
obj.attachedCell = attachedcell;
obj.btsInfo = importdata('btsInfo.mat');
end
when i try to call it in a nested for-loop, the second loop doesn't execute and an error occur : not enougth imput argument. The subclass baseStation seems not to receive arguments from last loop. I actually want to create an array object. Do someone tell me what I'm doing wrong?
thanks for your help
Bolivar

Réponses (1)

Muthu Annamalai
Muthu Annamalai le 27 Juin 2013
Modifié(e) : Muthu Annamalai le 27 Juin 2013

0 votes

Will you be posting the exact error message? That would help solve your problem.
I suspect you are running into problems with subscripting the object. Try instead, to create the first object as, a(1) = baseStation(args{:}) a(2) = baseStation(args{:})
should work and build what you are looking for.

4 commentaires

Bolivar
Bolivar le 27 Juin 2013
here the generated error "Not enough input arguments." and this happen at the second loop. That's right when subscribing instances out of a for loop as you specify it works. but i wanna be able to create variable size of that class what isn't possible that way. When you run the code i've provided, in the second loop the variable nargin indicate that there is no arguments passed to the constructor. The resuslt is seem at the matlab prompt.
Bolivar
Bolivar le 27 Juin 2013
I got to solve the problem. I just had to allow for no inputs arguments for both the constructor. then i could assign properties values for each instance. It's little bit combersome to assign the same value for each but i think i will be alright with it for the time being. Thanks for spending your time on that.
@Bolivar: What about using repmat()?
Bolivar
Bolivar le 1 Juil 2013
repmat just make copies of the given object. That's mean the resulting array all have the same handle(a change in one object's Property brings change in all the other) which isn't actually what i'm expecting then all object in the array should be unique. nevertheless thanks

Connectez-vous pour commenter.

Catégories

En savoir plus sur Construct and Work with Object Arrays dans Centre d'aide et File Exchange

Produits

Question posée :

le 27 Juin 2013

Community Treasure Hunt

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

Start Hunting!

Translated by