How can I repeat this line plot?

1 次查看(过去 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.

采纳的回答

Muhammad Usman Saleem
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
  3 个评论
Muhammad Usman Saleem
Your code is bucky can you point out where are the lines you wish to repeat?
Thomas
Thomas 2016-7-4
Thanks for the response Muhammad, I figured the problem out and my code is now fully functional.
Thanks again for your help!

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Resizing and Reshaping Matrices 的更多信息

标签

产品

Community Treasure Hunt

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

Start Hunting!

Translated by