1% Sparse operator for trimming. 2% 3% T = sparse_trim(sz1,m) 4% 5% Create a sparse operator which trim first and last row (or column) in 6% The field is a "collapsed" matrix of the size sz1. 7% 8% Input: 9% sz1: size of rhs 10% m: dimension to trim 11 12function T = sparse_trim(sz1,m) 13 14n1 = prod(sz1); 15 16sz2 = sz1; 17sz2(m) = sz2(m)-2; 18n2 = prod(sz2); 19 20n = length(sz1); 21 22% L1 23 24for i=1:n 25 vi{i} = 1:sz2(i); 26end 27 28IJ = cell(n,1); 29 30[IJ{:}] = ndgrid(vi{:}); 31 32for i=1:n 33 IJ{i} = IJ{i}(:); 34end 35 36L1 = sub2ind(sz2,IJ{:}); 37 38IJ{m}=IJ{m}+1; 39 40L2 = sub2ind(sz1,IJ{:}); 41 42one = ones(size(L1)); 43 44T = sparse(L1, L2, one, n2, n1); 45 46 47% Copyright (C) 2009 Alexander Barth <a.barth@ulg.ac.be> 48% 49% This program is free software; you can redistribute it and/or modify 50% it under the terms of the GNU General Public License as published by 51% the Free Software Foundation; either version 2 of the License, or 52% (at your option) any later version. 53% 54% This program is distributed in the hope that it will be useful, 55% but WITHOUT ANY WARRANTY; without even the implied warranty of 56% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 57% GNU General Public License for more details. 58% 59% You should have received a copy of the GNU General Public License 60% along with this program; If not, see <http://www.gnu.org/licenses/>. 61 62