matrix - Matlab, define submatrix -
i got 10x10 matrix bunch of zeroes , element of value 1. i'm trying create submatrix element of 1 , surrounding.
problem:
this example, element "1" placed anywhere within matrix. realise can find element using find find(matrix==1)
.
how define 3x3 submatrix?
you need use 'find' indices of '1' element, , construct desired matrix them. like:
[row, col] = find(matrix==1); submatrix = matrix(row-1:row+1, col-1:col+1);
of course, might need check '1' element not in border of matrix (i.e. row-1, row+1, col-1, col+1 not out of bounds).
best.
Comments
Post a Comment