% cleangrid - clean up matrix with grid line of same value % % Usage: % [cleanMatrix,rowIndex,colIndex] = cleangrid(gridMatrix,gridValue) % % % Arguments: % gridMatrix - the matrix to be cleaned % gridValue - the grid value % % Output: % cleanMatrix - the cleaned up matrix, smaller size % rowIndex - the row index that grid lines have been cleaned % colIndex - the column index that grid lines have been cleaned % % See also addgrid.m % Author: % Tzu Yen Wong % wongt AT csse DOT uwa DOT edu DOT au % Department of Computer Science & Software Engineering % The University of Western Australia % % Nov 2003 % June 2004 change email address to fight SPAM!!! %1234567890123456789012345678901234567890123456789012345678901234567890123456789 function [cleanMatrix,rowIndex,colIndex] = cleangrid(gridMatrix,gridValue) grid = (gridMatrix==gridValue); colIndex = find(sum(~grid,1)==0); colIndex = colIndex(:)'; rowIndex = find(sum(~grid,2)==0); rowIndex = rowIndex(:)'; lengthc = length(colIndex); lengthr = length(rowIndex); for ii=lengthr:-1:1, grid_ii = rowIndex(ii); gridMatrix(grid_ii:end-1,:) = gridMatrix(grid_ii+1:end,:); end for jj=lengthc:-1:1, grid_jj = colIndex(jj); gridMatrix(:,grid_jj:end-1) = gridMatrix(:,grid_jj+1:end); end cleanMatrix = gridMatrix(1:end-lengthr,1:end-lengthc);