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:

enter image description here

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

Popular posts from this blog

PHPMotion implementation - URL based videos (Hosted on separate location) -

c# - Unity IoC Lifetime per HttpRequest for UserStore -

I am trying to solve the error message 'incompatible ranks 0 and 1 in assignment' in a fortran 95 program. -