Vector Operation in Matlab? -
can body me explain line 7 of code. line
temp(min(temp,[],2) >=1 & max(temp,[],2)<=n,:)
do in code?
line 7 of code throwing me off
n=10; h=-1; j=0; i=1:n 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
that line selecting rows of temp
have values between 1
, n
, , assigning submatrix ngh{i,j}
.
note that
min(...,[],2)
ormax(...,[],2)
gives minimum or maximum of each row;- the logical comparison
1
orn
,&
operation result in logical index vector, used address desired rows oftemp
(and columns).
Comments
Post a Comment