How can I repeat this line plot?

1 Ansicht (letzte 30 Tage)
Thomas
Thomas am 30 Jun. 2016
Kommentiert: Thomas am 4 Jul. 2016
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.

Akzeptierte Antwort

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

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Resizing and Reshaping Matrices finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by