1% Create a sparse matrix which packs an array under the control of a mask. 2% 3% H = sparse_pack(mask) 4% 5% Create a sparse matrix H which packs an array. It selects the elements where 6% mask is true. 7 8function H = sparse_pack(mask) 9 10 11j = find(mask)'; 12m = length(j); 13i = 1:m; 14s = ones(1,m); 15 16n = numel(mask); 17 18%whos i j s 19H = sparse(i,j,s,m,n); 20 21% Copyright (C) 2009 Alexander Barth <a.barth@ulg.ac.be> 22% 23% This program is free software; you can redistribute it and/or modify 24% it under the terms of the GNU General Public License as published by 25% the Free Software Foundation; either version 2 of the License, or 26% (at your option) any later version. 27% 28% This program is distributed in the hope that it will be useful, 29% but WITHOUT ANY WARRANTY; without even the implied warranty of 30% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 31% GNU General Public License for more details. 32% 33% You should have received a copy of the GNU General Public License 34% along with this program; If not, see <http://www.gnu.org/licenses/>. 35 36