MATLAB: Matrix index is out of range for deletion

ge functioninequality

Hello Guys! Consider a matrix n by 7 such as A and assume B=A. The following command works fine for i=1:n
B(B(:,1)~=A(i,1) & B(:,2)>=A(i,2) & B(:,3)>=A(i,3) & B(:,4)>=A(i,4) & B(:,5)<=A(i,5) & B(:,6)<=A(i,6) & B(:,7)<=A(i,7),:)=[];
However when I merge it to the following command I get "Matrix index is out of range for deletion.".
B(B(:,1)~=A(i,1) & B(:,2:4)>=A(i,2:4) & B(:,5:7)<=A(i,5:7),:)=[];
# Any help how to make the first command shorter without increasing the calculated time?
for example if the number of columns increases to 11, the command is as follows, which is so long, and for any changing in the number of columns, a new command should be written.
B(B(:,1)~=A(i,1) & B(:,2)>=A(i,2) & B(:,3)>=A(i,3) & B(:,4)>=A(i,4) & B(:,5)<=A(i,5) & B(:,6)<=A(i,6) & B(:,7)<=A(i,7) & B(:,8)<=A(i,8) & B(:,9)<=A(i,9) & B(:,10)<=A(i,10) & B(:,11)<=A(i,11),:)=[];
Thank you

Best Answer

[EDIT]
MATLAB >= R2016b
B = permute(A,[3,2,1]);
out = A(all(any([A(:,1) == B(:,1,:),A(:,2:4) < B(:,2:4,:),A(:,5:end) > B(:,5:end,:)],2),3),:);
and with bsxfun (all versions of MATLAB):
lo = [bsxfun(@eq,A(:,1),B(:,1,:)), bsxfun(@lt,A(:,2:4),B(:,2:4,:)),bsxfun(@gt,A(:,5:end),B(:,5:end,:))];
out = A(all(any(lo,2),3),:)