
function xnew   = remap2d(x,is,js, newsize); 
% function xnew = remap2d(x,is,js, [newsize]) 
% uses the i,j pairs to load values from x into the 2d version xnew. 
% If newsize is given, then size(xnew) = newsize = [newsize(1) newsize(2)]. 
%  ... otherwise, size(xnew) = [max(is), max(js)].
% Note, all unassigned values of xnew will be zeros. 
%

if ~exist('newsize','var'), 
 newsize = [max(is(:)) max(js(:))]; 
end; 

xnew = zeros(newsize); 

w = find(is); 
index = sub2ind(newsize, is,js); 
xnew(index) = x(w); 

% that's it ! 
 


