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?

답변 (2개)

Matt J
Matt J 2015년 7월 1일
편집: Matt J 2015년 7월 1일
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;

카테고리

도움말 센터File Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

질문:

2015년 7월 1일

댓글:

2015년 7월 1일

Community Treasure Hunt

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

Start Hunting!

Translated by