Reputation: 39
In MATLAB, if we assume the starting point of a cube is up-left corner,
3D_vol(Start_x : Start_x + SizeX-1, Start_y : Start_y + SizeY-1, Start_z : Start_z + SizeZ-1);
gets a cube having starting points of X, Y, Z and size of each. Now, if the starting point is the center of the cube, how can I get the cube?
I tried the following, but it is not correct when the size of X/Y/Z is even.
3D_vol(start_x - (SizeX/2) - 1 : Start_x + (SizeX/2) - 1, ......
3D_vol is a 3d matrix.
Upvotes: 0
Views: 101
Reputation: 2332
I am assuming the start points are integers.
If SizeX
is odd it is easier. You have you centre point and (SizeX-1)/2
in each side:
start_x + (-(SizeX-1)/2:(SizeX-1)/2)
That would give you a total of 1+2*(SizeX-1)/2 = SizeX
points.
In case SizeX
is even, your start_x is not actually the centre but one of the closest points to it. You should decide if its left or right of centre. Let's assume left. Then, on the left side you need the start_x point and SizeX/2-1
more points. the rest would be on the right:
start_x + (-(SizeX/2-1):SizeX/2)
That would give you a total of 1+(SizeX-1)/2-1+SizeX/2 = SizeX
points.
Upvotes: 1