Hi everyone,
I have what I feel is a simple problem but I just can't find a fast, vectorized way to split a 3d volume along the z indicies defined in a matrix, as described below.
I have a volume [X Y Z] in which in find an arbitrary surface. This surface has the dimension [X Y] and the value at each positon in said surface tells me where to split my volume along z. Here is the naive for-loop approach, but it's sloooow (I have many volumes and they are much larger than in this example).
volume = rand(500,600,300);surface = round(rand(500,600).*150+1);tic;[topVol,botVol] = split_volume(volume,splitDepth);done(toc);function [topVol,botVol] = split_volume(volData,Z) [nX,nY,~] = size(volData); topVol = volData; botVol = volData; for iX = 1:nX for iY = 1:nY zIdx = Z(iX,iY); topVol(iX,iY,zIdx:end) = 0; botVol(iX,iY,1:zIdx) = 0; end endend
Best Answer