How to have a plot3 vector and sphere on same figure?
Afficher commentaires plus anciens
Hello all, I'm currently trying to write a program where I'm drawing a line within a sphere, and it changes size based on the dataset. The line will always start at the origin, but I want the line to dynamically change based on the endpoint given, which will be given by a dataset. The problem I'm running into is that I can't get this line to be on the same figure as the sphere, even with hold on. when it did work previously, it just traced a path and left it there, which obscured the motion of the vector throughout the space. I've posted the code below, and any help would be appreciated.
figure(1) %creating animation window
sphere % creating sphere for visualization
alpha('clear') % making sphere clear for visualization
hold on; % make it so that all animations are drawn on same figure
for k=1:1200 %looping through data set
v = z(k); % z coordinate
vec1 = [0,0,0];
vec2 = [0,0,v];
vec = [vec2;vec1];
figure(1);
h = plot3(vec(:,1),vec(:,2),vec(:,3), 'LineWidth', 2, 'Color', 'r');%updating the line animation data set
clf(h, 'reset');
refreshdata;
drawnow;
end
Réponse acceptée
Plus de réponses (1)
Maxwell DeVoe
le 25 Juil 2018
0 votes
2 commentaires
Ryan Takatsuka
le 25 Juil 2018
No, but it should work with any vector of z values (You might have to change the indexing of the for-loop to loop over z depending on the length of the vector).
Maxwell DeVoe
le 25 Juil 2018
Catégories
En savoir plus sur Animation dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!