function list = insertList(list,object); %insertList - inserts an object into a list of objects % % Parameter: list The list to be modified % Parameter: object The object to be inserted % Returns: list The modified list % % Example(s): % thelist=insertList(thelist,temp_object); % %% =========================================================================== %% =========================================================================== % Copyright (C): % 1999 by Telia Research AB, Lulea, Sweden; % 2000-2002 by Forschungszentrum Telekommunikation Wien, Austria; % All rights reserved. % Project : The FTW simulator % Author(s) : Tomas Nordstrom (Tomas.Nordstrom@FTW.at) % % CVS: $Id: insertList.m,v 1.6 2002/03/18 11:59:42 tono Exp $ %% =========================================================================== % Change History % 1999-02-25 (ToNo) Created % 2002-03-18 (ToNo) Made insertList overwrite existing objects %% =========================================================================== len = length(list); if len==0, list=object; else % Check if there is an object with the same name already found_idx=find(strcmp({list.name},object.name)); if isempty(found_idx) % If new add object to the end of the list list(len+1)=object; else % If existing overwrite the object len_found_idx=length(found_idx); if len_found_idx>1 warning(sprintf('There are multiple entries of object %s in the list!', object.name)); end % Choose first entry if list has multiple entries with the same name list(found_idx(1)) = object; % Choose last entry if list has multiple entries with the same name % list(found_idx(len_found_idx))=object; end end;