view general/arrutils/defmat.m @ 6:0ce3c2070089

Removed duplicate code and fixed doc in timed_action.
author samer
date Mon, 14 Jan 2013 14:33:37 +0000
parents e44f49929e56
children
line wrap: on
line source
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