0001 function [NEWLATTICE, SHIFTEDKEEPINDEX, SHIFTEDREFINDEX] = combinebypassmethod(LATTICE,METHOD,KEEPINDEX,REFINDEX)
0002
0003
0004
0005
0006
0007 OLDN = length(LATTICE);
0008
0009 I45 = findcells(LATTICE,'PassMethod',METHOD);
0010
0011 D = diff(I45);
0012
0013 A = 1:length(LATTICE);
0014 A(I45(find(~(D-1))))=0;
0015
0016 A = ~A;
0017
0018
0019
0020
0021
0022 if ~isempty(KEEPINDEX)
0023 A(KEEPINDEX)=0;
0024 K = KEEPINDEX-1;
0025 if K(1)<1
0026 A(K(2:end))=0;
0027 else
0028 A(K)=0;
0029 end
0030 else
0031 SHIFTEDKEEPINDEX = [];
0032 end
0033
0034 if ~isempty(REFINDEX)
0035 R = REFINDEX-1;
0036 if R(1)<1
0037 A(R(2:end))=0;
0038 else
0039 A(R)=0;
0040 end
0041 else
0042 SHIFTEDREFINDEX = [];
0043 end
0044
0045 CSA = cumsum(A);
0046
0047 SHIFTEDKEEPINDEX = KEEPINDEX-CSA(KEEPINDEX);
0048
0049 if ~isempty(REFINDEX)
0050 if REFINDEX(1)<2
0051 SHIFTEDREFINDEX = REFINDEX-[0 CSA(REFINDEX(2:end)-1)];
0052 else
0053 SHIFTEDREFINDEX = REFINDEX-CSA(R);
0054 end
0055 end
0056
0057
0058 SHIFTEDREFINDEX = REFINDEX-CSA(REFINDEX-1) ;
0059
0060
0061 NEWN = CSA(end);
0062 NEWLATTICE = cell(1,NEWN);
0063
0064 NEWLATTICE{1}=LATTICE{1};
0065 writepos = 1;
0066 for i=2:OLDN
0067 if A(i-1)
0068 NEWLATTICE{writepos}.Length = NEWLATTICE{writepos}.Length+LATTICE{i}.Length;
0069 else
0070 writepos = writepos+1;
0071 NEWLATTICE{writepos}=LATTICE{i};
0072 end
0073 end