GETGOODSUBRECT extracts a grid subset of the input grid such that the output grid does not contain any bad points. GETGOODSUBRECT takes as input a MxNx2 matrix acting a chessboard grid. It also takes two vectors containing the x and y coordinates of the bad points. The two vectors must be the same size. The result returned is suboptimal. Optimal algorithms introduce complexity beyond our basic requirements. USAGE: gridout=getgoodsubrect(grid,badptsx,badptsy); INPUTS: grid: MxNx2 chessboard grid badptsx: x coordinates of the bad points badptsy: y coordinates of the bad points OUTPUTS: gridout: a subset of the input grid without any bad points
0001 function gridout=getgoodsubrect(grid,badptsx,badptsy) 0002 %GETGOODSUBRECT extracts a grid subset of the input grid such that the output grid does not contain any bad points. 0003 % 0004 % GETGOODSUBRECT takes as input a MxNx2 matrix acting a chessboard grid. 0005 % It also takes two vectors containing the x and y coordinates of the bad 0006 % points. The two vectors must be the same size. 0007 % 0008 % The result returned is suboptimal. Optimal algorithms introduce 0009 % complexity beyond our basic requirements. 0010 % 0011 % USAGE: 0012 % gridout=getgoodsubrect(grid,badptsx,badptsy); 0013 % 0014 % INPUTS: 0015 % grid: MxNx2 chessboard grid 0016 % 0017 % badptsx: x coordinates of the bad points 0018 % 0019 % badptsy: y coordinates of the bad points 0020 % 0021 % OUTPUTS: 0022 % gridout: a subset of the input grid without any bad points 0023 0024 0025 xmin=1; 0026 xmax=size(grid,1); 0027 ymin=1; 0028 ymax=size(grid,2); 0029 0030 for i=1:length(badptsx) 0031 dist=[badptsx(i)-1,badptsy(i)-1,size(grid,1)-badptsx(i),size(grid,2)-badptsy(i)]; 0032 [minval,minindx]=min(dist); 0033 switch minindx 0034 case 1 0035 if badptsx(i)>=xmin 0036 xmin=badptsx(i)+1; 0037 end 0038 case 2 0039 if badptsy(i)>=ymin 0040 ymin=badptsy(i)+1; 0041 end 0042 case 3 0043 if badptsx(i)<=xmax 0044 xmax=badptsx(i)-1; 0045 end 0046 case 4 0047 if badptsy(i)<=ymax 0048 ymax=badptsy(i)-1; 0049 end 0050 end 0051 end 0052 0053 gridout=grid(xmin:xmax,ymin:ymax,:);