function md = subsasgn(md,index,val)
%SUBSASGN - handle indexed assignments to objects
%
%   the first argument is the object, the second argument a structure array
%   the third one is the value
%
%   Usage:
%      md = subsasgn(md,index,val)
%
%   See also SUBSREF

if ~isempty(md.repository),
	field=index(1).subs;
	if exist(['.' md.repository '.' field],'file'),
		if length(index)==1,
			%save val in corresponding repository
			eval([field '=val;']);
			eval(['save .' md.repository '.' field ' ' field]);
		else
			%load field from file
			load(['.' md.repository '.' field],'-mat');
			fieldval=eval(field);
			eval([field '=builtin(''subsasgn'',fieldval,index(2),val);']);
			eval(['save .' md.repository '.' field ' ' field]);
		end
	else
		md=builtin('subsasgn',md,index,val);
	end
else
	md=builtin('subsasgn',md,index,val);
end
