How can I repeat this line plot?
2 ビュー (過去 30 日間)
表示 古いコメント
Hi everyone,
The code I am using is
clear all;
a0 = 1;
b0 = a0./4 .* [1 1 1];
a1 = a0./2 .* [0 1 1];
a2 = a0./2 .* [1 0 1];
a3 = a0./2 .* [1 1 0];
N1=2;
N2=2;
N3=2;
In = zeros(N1,N2,N3,3);
P = zeros(N1,N2,N3,3);
for n = 0:N1-1
for m = 0:N2-1
for l = 0:N3-1
In(n+1,m+1,l+1,1:3) = n.*a1+m.*a2+l.*a3;
P(n+1,m+1,l+1,1:3) = n.*a1+m.*a2+l.*a3 + b0;
end
end
end
In_plt = reshape(In,[N1*N2*N3,3]);
hold off
scatter3(In_plt(:,1),In_plt(:,2),In_plt(:,3), 'b','filled');
P_plt = reshape(P,[N1*N2*N3,3]);
hold on
scatter3(P_plt(:,1),P_plt(:,2),P_plt(:,3), 'r','filled');
line([P(1,1,1,1) In(1,1,1,1)],[P(1,1,1,2) In(1,1,1,2)],[P(1,1,1,3) In(1,1,1,3)]);
line([P(1,1,1,1) In(1+1,1,1,1)],[P(1,1,1,2) In(1+1,1,1,2)],[P(1,1,1,3) In(1+1,1,1,3)]);
line([P(1,1,1,1) In(1,1+1,1,1)],[P(1,1,1,2) In(1,1,1,2)],[P(1,1,l+1,3) In(1,1+1,1,3)]);
line([P(1,1,1,1) In(1,1,1,1)],[P(1,1,1,2) In(1,1,1+1,2)],[P(1,1,1,3) In(1,1,1+1,3)]);
hold off
view(3), axis vis3d
axis off
camproj perspective, rotate3d on
title('Diamond structure of Indium Phosphide')
And this produces

What I want to happen is to connect all of these points using line. The section of code which produces the line connections is
line([P(1,1,1,1) In(1,1,1,1)],[P(1,1,1,2) In(1,1,1,2)],[P(1,1,1,3) In(1,1,1,3)]);
line([P(1,1,1,1) In(1+1,1,1,1)],[P(1,1,1,2) In(1+1,1,1,2)],[P(1,1,1,3) In(1+1,1,1,3)]);
line([P(1,1,1,1) In(1,1+1,1,1)],[P(1,1,1,2) In(1,1,1,2)],[P(1,1,l+1,3) In(1,1+1,1,3)]);
line([P(1,1,1,1) In(1,1,1,1)],[P(1,1,1,2) In(1,1,1+1,2)],[P(1,1,1,3) In(1,1,1+1,3)]);
What can I do to reproduce this section of code for every connection?
Thanks in advance.
0 件のコメント
採用された回答
Muhammad Usman Saleem
2016 年 6 月 30 日
why you do not copy paste it into code, i think due to bluck in coding
try to access these lines through for loop.
Check it
その他の回答 (0 件)
参考
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!