Selecting a region from a 3D matrix and replacing the values there.
Ältere Kommentare anzeigen
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?
Antworten (2)
For a 5x5x5 neighborhood centered at (i0,j0,k0), you could do:
e=-2:2;
yourArray(i0+e,j0+e,k0+e)=1;
Andrei Bobrov
am 1 Jul. 2015
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;
1 Kommentar
Alex sturt
am 1 Jul. 2015
Kategorien
Mehr zu Matrices and Arrays finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!