0001 function gridout=adjgriddir(grid)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017 warning('off','MATLAB:polyfit:PolyNotUnique');
0018 warning('off','MATLAB:polyfit:RepeatedPointsOrRescale');
0019
0020 rowslope=zeros(1,size(grid,1));
0021 colslope=zeros(1,size(grid,2));
0022
0023
0024 for rowindx=1:size(grid,1)
0025 currentrowx=grid(rowindx,:,1);
0026 currentrowy=grid(rowindx,:,2);
0027 currentrowx=currentrowx(currentrowx>0);
0028 currentrowy=currentrowy(currentrowy>0);
0029 P=polyfit(currentrowx,currentrowy,1);
0030 rowslope(rowindx)=abs(P(1));
0031 end
0032
0033
0034 for colindx=1:size(grid,2)
0035 currentcolx=grid(:,colindx,1);
0036 currentcoly=grid(:,colindx,2);
0037 currentcolx=currentcolx(currentcolx>0);
0038 currentcoly=currentcoly(currentcoly>0);
0039 P=polyfit(currentcolx,currentcoly,1);
0040 colslope(colindx)=abs(P(1));
0041 end
0042
0043
0044 warning('on','MATLAB:polyfit:PolyNotUnique');
0045 warning('on','MATLAB:polyfit:RepeatedPointsOrRescale');
0046
0047 rowslope=mean(rowslope);
0048 colslope=mean(colslope);
0049
0050
0051 if colslope>rowslope
0052 gridtemp(:,:,1)=rot90(grid(:,:,1));
0053 gridtemp(:,:,2)=rot90(grid(:,:,2));
0054 gridout=gridtemp;
0055 else
0056 gridout=grid;
0057 end