Reputation: 945
Can any body help me explain Line 7 of this code. What does this line
temp(min(temp,[],2) >=1 & max(temp,[],2)<=N,:)
do in the code?
Line 7 of this code is throwing me off
N=10;
H=-1;
J=0;
for i=1:N
for j=1:N
temp=[i-1,j;i+1,j;i,j-1;i,j+1];
ngh{i,j}=temp(min(temp,[],2) >=1 & max(temp,[],2)<=N,:);
end
end
Upvotes: 0
Views: 50
Reputation: 112769
That line is selecting the rows of temp
which have all values between 1
and N
, and assigning that submatrix to ngh{i,j}
.
Note that
min(...,[],2)
or max(...,[],2)
gives the minimum or maximum of each row;1
or N
and the &
operation result in a logical index vector, which is used to address the desired rows of temp
(and all columns).Upvotes: 3