2013-10-28 79 views

回答

1

您描述的問題與您發佈的論文不同。我遵循你的描述,但將其分成多行,以便您可以輕鬆地將其調整爲符合您的要求。

這與the MatLab answer非常相似,有人發佈在您的其他問題。我不知道任何類似於SciLab中的mat2cellcellfun的其他答案。

clear; clc 

K = 100 
N = 5 

mid = floor(N/2) 

volume = rand(K, K, K) 
cubeCount = floor(K/N) 

for x=0:cubeCount-1 
    for y=0:cubeCount-1 
     for z=0:cubeCount-1 

      // Get a cube of NxNxN size 
      cube = volume((1:N)+N*x, (1:N)+N*y, (1:N)+N*z); 

      //Calculate the average value of the voxels in the cube 
      avg = sum(cube)/(N * N * N); 

      // Assign it to the center voxel 
      volume(N*x+mid+1, N*y+mid+1, N*z+mid+1) = avg 
     end 
    end 
end 

disp(volume)