Info
이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.
develop plotting from 2D to 3D
조회 수: 5 (최근 30일)
이전 댓글 표시
Hi,
If I have a matrix in 3D and it contains only either 1 or 0. If any 1's neighbour either in X direction, Y direction or Z direction, I want to represent it these (1)s as a line. Actually, one of friends programmed it for 2D for me. I want to know how can I make it applicable for 3D.

Here is his code for 2D only.
U3 = [
0 , 1 , 0 , 0 , 0;
0 , 1 , 0 , 0 , 0;
0 , 1 , 0 , 0 , 1;
1 , 1 , 0 , 0 , 1;
1 , 0 , 0 , 0 , 0
]
[r, c, v]=size(U3);
figure
for cIdx=1:c,
y=find(U3(:,cIdx)==1);
if length(y)>1
y=(r+1)-y;
x=ones(size(y))*cIdx;
for idx=1:length(x)-1
if abs( y(idx) - y(idx+1))<=1
line(x(idx:idx+1),y(idx:idx+1),'LineWidth',4)
end
end
hold on
end
end
for rIdx=1:r,
x=find(U3(rIdx,:)==1);
if length(x)>1
y=(r+1)-ones(size(x))*rIdx;
for idx=1:length(x)-1
if abs( x(idx) - x(idx+1))<=1
line(x(idx:idx+1),y(idx:idx+1),'LineWidth',4)
end
end
hold on
end
end
In my case, I want to do it for 3D. Could you please advice me?
Here is a 3D matrix:
U3(:,:,1) = [
0 , 0 , 0 , 0 , 0;
0 , 0 , 0 , 0 , 0;
0 , 1 , 0 , 0 , 1;
0 , 0 , 0 , 0 , 1;
0 , 0 , 0 , 0 , 0
]
U3(:,:,2) = [
0 , 0 , 0 , 0 , 0;
0 , 0 , 0 , 0 , 0;
0 , 1 , 0 , 0 , 0;
0 , 1 , 0 , 0 , 1;
0 , 1 , 0 , 0 , 0
]
U3(:,:,3) = [
0 , 0 , 0 , 0 , 0;
0 , 0 , 0 , 0 , 0;
0 , 1 , 0 , 0 , 0;
0 , 0 , 0 , 0 , 1;
0 , 0 , 0 , 0 , 1
]
댓글 수: 2
답변 (0개)
이 질문은 마감되었습니다.
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!