Unsatisfied answer and no errors
Show older comments
Hi,
I am new to the Matlab and I want to develop a 10X10X10 voxel(cube) function programme and set all the voxels on the edges "1" and rest(internal voxels)as "0". Then I have to develop a function to calculate the ratio of "1" and "0" and validate my answer using the hand calculations. I have developed a function to find the voxels on the edges(1) and rest as (0).but i am not satisfied with my answer. there is no error.but the answer is wrong(sum of the voxels on the edges and sum of the internal voxels are wrong). I have selected i,j,k values that matches with the voxels on the edges(1) and internal voxels(0) as below programme written by me using the hand skethced diagram.Appreciate your comments.
b=zeros(10,10,10);
for i=1:10
for j=1:10
for k=1:10
if ((i ==1) || (i==2) || (i==3)||(i==4)||(i==5)||(i ==6) || (i==7) || (i==8)||(i==9)||(i==10)) && ((j==1) || (j==10)) && ((k==1) || (k==10))
b(i,j,k)=1;
else
b(i,j,k)=0;
if ((i ==1) || (i==10)) && ((j==2) || (j==3) || (j==4)||(j==5) || (j==6) || (j==7)||(j==8) || (j==9)) &&( (k==1) || (k==10))
b(i,j,k)=1;
else
b(i,j,k)=0;
if ((i ==1) || (i==10)) && ((k==2) || (k==3) || (k==4)|| (k==5) || (k==6) || (k==7)||(k==8) || (k==9)) && ((j==1) || (j==10))
b(i,j,k)=1;
else
b(i,j,k)=0;
end
end
end
end
end
end
sum b(i,j,k)=1
sum b(i,j,k)=0
note---sum b(i,j,k)=1 shown as 695 and sum b(i,j,k)=0 shown as 694 which is totally wrong.(695+694 is not equal to 10X10X10)
Accepted Answer
More Answers (0)
Categories
Find more on Resizing and Reshaping Matrices in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!