How can I repeat this line plot?
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Thomas
le 30 Juin 2016
Commenté : Thomas
le 4 Juil 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
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/154605/image.png)
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 commentaires
Réponse acceptée
Muhammad Usman Saleem
le 30 Juin 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 commentaires
Muhammad Usman Saleem
le 1 Juil 2016
Your code is bucky can you point out where are the lines you wish to repeat?
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Resizing and Reshaping Matrices dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!