Question

I have a scilab program for averaging a 3D matrix and it works ok.However, instead of having the average just be a set value.I want it to be a certain sum of mass(sum(n*n*n).

K = 100
N = 5
A = 1 

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 = 20;


            //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 )

If anyone has a simple solution to this, please tell me.

Was it helpful?

Solution

You seem to have just about said it your self. All you would need to do would be change cube to equal.

cube = while sum(A * A * A) < 10,

A=A+1;

This will give you the correct sum of mass of the voxels.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top