I want to create a 3D matrix

I want to create a 3D matrix A(10*10*10) then subdivide(1*1*1) it and then give some property to few elements(say at (5,6,10)&(6,6,10) A = 5; else A=0;) and then see this.

댓글 수: 7

Image Analyst
Image Analyst 2018년 1월 20일
This is what I have written so far
del_x = 1; del_y = 1; del_z = 1;%subdivisions of cube
xi = 1:del_x:10; yj = 1:del_y:10; zk = 1:del_z:10; %dimensions of the cube
N = length(xi); P = length(yj); Q = length(zk);
l=1;
% calculating mid ordinates of each cube
for k = 1:Q
for j = 1:P
for i = 1:N
x = xi(i); y = yj(j);z = zk(k);
X_mid(l) = x + del_x/2;
Y_mid(l) = y + del_y/2;
Z_mid(l) = z + del_z/2;
l=l+1;
end
end
end
l=1;
for k = 1:Q
for j = 1:P
for i = 1:N
if (((X_mid(l)==5.5)||(X_mid(l) == 6.5))&&(Y_mid(l)==6.5)&&((Z_mid(l)==3.5)||(Z_mid(l)==10.5)))
A(i,j,k)= 5;
else A(i,j,k) = 0;
end
l=l+1;
end
end
end
Can anyone tell me how I can view my A matrix as a 3D figure
Walter Roberson
Walter Roberson 2018년 1월 20일
Be careful with comparing floating point values using the bit-for-bit equality operator == . Consider using ismembertol() instead.
Walter Roberson
Walter Roberson 2018년 1월 20일
See vol3d in the File Exchange.
Shivangi
Shivangi 2018년 1월 20일
Are you saying vol3d v2 by Oliver Woodford?
Walter Roberson
Walter Roberson 2018년 1월 20일
Sure.
Shivangi
Shivangi 2018년 1월 21일
편집: Walter Roberson 2018년 1월 21일
I want an output like this , for this I am making a meshgrid of x,y,z.
Now I want few cubes (4 as given in the figure) to have different values and others remain zero .
Is it possible to do it in MATLAB and generate such type of 3D result? Can you point me how to approach such problem.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

태그

질문:

2018년 1월 20일

편집:

2018년 1월 21일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by