function RespObj = namesys(RespObj)
%NAMESYS  Names the LTI system variables in Response Objects.

%   Karen Gondoly
%   Copyright 1986-2000 The MathWorks, Inc. 
%   $Revision: 1.2 $   $Date: 2000/06/14 20:07:29 $


SysNames = RespObj.SystemNames;
ContextMenu = RespObj.UIContextMenu;

%---Replace empty names by untitledXX
indEN = find(strcmpi('',SysNames));
if ~isempty(indEN),
   %---Look for existing "untitled" strings
   Untitled = find(strncmpi('untitled',SysNames,8));
   UntitledStr = char(SysNames(Untitled));
   UsedInds = zeros(size(Untitled));
   for i=1:length(Untitled),
      UsedInds(i) = str2double(UntitledStr(i,9:end));
   end
   AvailInds = (1:max([length(SysNames) , max(UsedInds)]))';
   AvailInds(UsedInds,:) = [];
   % Replace '' by untitledXX
   SysNames(indEN,:) = ...
      strcat({'untitled'},cellstr(strjust(num2str(AvailInds(1:length(indEN),:)),'left')));
end
RespObj.SystemNames = SysNames;

% Create context menu entries for new systems
NumSys0 = length(ContextMenu.Systems.Names);
for k=NumSys0+1:length(SysNames),
   ContextMenu.Systems.Names(k) = uimenu(ContextMenu.Systems.Main,...
      'Label',SysNames{k},...
      'Checked','on',...   
      'Callback',['menufcn(''systemtoggle'')']);
end
RespObj.UIContextMenu = ContextMenu;