Selecting a region from a 3D matrix and replacing the values there.

I have a 100 * 100* 200 matrix, all as 0's, I want to select a 5x5x5 set of numbers with in this to turn in to 1's, how do I do this?

Answers (2)

For a 5x5x5 neighborhood centered at (i0,j0,k0), you could do:
e=-2:2;
yourArray(i0+e,j0+e,k0+e)=1;
z = zeros(10,10,10); % Let your array
ii = [3 4 2];
d = 5;
c = arrayfun(@(x,y)x:y,ii,ii+5,'un',0);
z(c{:}) = 1;

Categories

Asked:

on 1 Jul 2015

Commented:

on 1 Jul 2015

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!