Info
La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.
develop plotting from 2D to 3D
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
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.
![](https://www.mathworks.com/matlabcentral/images/broken_image.png)
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 comentarios
Respuestas (0)
La pregunta está cerrada.
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!