function X=defmat(I,w,D)
% defmat - specify matrix as a list of non-zero elements
%
% defmat ::
%    [[N,E]->natural]   ~'N E-dim array subscripts, 1 per row',
%    [[N]]              ~'values to place at positions specified by subs',
%    D:[[1,E]]          ~'size of target array'
% -> [[D]]              ~'array of size D'.

X=accumarray(I,w);
if any(size(X)<D)
	J=num2cell(D);
	X(J{:})=0;
end
