trimColumns

PURPOSE ^

trim the columns of the input matrix to equal values

SYNOPSIS ^

function matrix = trimColumns(matrix, zerotol)

DESCRIPTION ^

 trim the columns of the input matrix to equal values

 THIS FUNCTION IS NO USER FUNCTION.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function matrix = trimColumns(matrix, zerotol)
0002 % trim the columns of the input matrix to equal values
0003 %
0004 % THIS FUNCTION IS NO USER FUNCTION.
0005 
0006 % The elk-library: convex geometry applied to crystallization modeling.
0007 %   Copyright (C) 2012 Alexander Reinhold
0008 %
0009 % This program is free software: you can redistribute it and/or modify it
0010 %   under the terms of the GNU General Public License as published by the
0011 %   Free Software Foundation, either version 3 of the License, or (at your
0012 %   option) any later version.
0013 %
0014 % This program is distributed in the hope that it will be useful, but
0015 %   WITHOUT ANY WARRANTY; without even the implied warranty of
0016 %   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0017 %   General Public License for more details.
0018 %
0019 % You should have received a copy of the GNU General Public License along
0020 %   with this program.  If not, see <http://www.gnu.org/licenses/>.
0021 
0022 %% info
0023 % Values that are close to each other, like (1+zerotol) equals 1, are
0024 %   trimmed to be exactly equal. Afterwards unique(matrix, 'rows') can be
0025 %   used to obtain a simplified matrix.
0026 
0027 % iterate over columns
0028 for iCol = 1:size(matrix, 2)
0029     
0030     % sort the current column
0031     [thisCol, originalRowVector] = sort(matrix(:, iCol));
0032     
0033     % cycle through the group of equal entries
0034     iRow = 1;
0035     while iRow < size(matrix, 1)
0036         % get the indices that are almost equal to the first one
0037         filterInTol = abs(thisCol - thisCol(iRow)) < zerotol;
0038         
0039         % set the original row entries to be equal
0040         matrix(originalRowVector(filterInTol), iCol) = thisCol(iRow);
0041         
0042         % update the row index
0043         iRow = find(filterInTol, 1, 'last') + 1;
0044     end
0045     
0046 end

Generated on Sat 18-Jul-2015 16:45:31 by m2html © 2005