Plot 3D Animation
Show older comments
Good morning,
I am currently developing my master thesis in MATLAB, developing an academic Multibody Systems algorithm. I am currently having some difficulties doing my debug and I was trying to code a 3D Animated Plot to try and understand what was my system behaviour.
This is my current code:
%% 3D Animation Plot
if strcmp(anigraph,'yes') == 1 || strcmp(anigraph,'YES') == 1 || strcmp(anigraph,'Yes') == 1
NPoint = Joints.NPoint; %Number of Points
origin = [0,0,0]; %Origin
%% Plot the Graphic
for f = 1:1667:c %Size of the Point StructStruct
%Plot First two Points of each iteration
strucPos = Points{1,f};
vecpos = strucPos(2).Position;
vecpos = vecpos';
%Initiate the 3D Plot
m = plot3([origin(1) vecpos(1)],[origin(2) vecpos(2)],[origin(3) vecpos(3)],'LineWidth',2);
hold on
axis auto
grid on
%Retrieve the Position Information and plot
for h = 2:NPoint
% Previous Point Pos Vector
prevecpos = strucPos(h-1).Position;
prevecpos = Impose_Column(prevecpos);
prevecpos = prevecpos';
% Foward Point Pos Vector
vecpos = strucPos(h).Position;
vecpos = Impose_Column(vecpos);
vecpos = vecpos';
%Plot These Points
plot3([prevecpos(1) vecpos(1)],[prevecpos(2) vecpos(2)],[prevecpos(3) vecpos(3)],'LineWidth',2),
hold on
pause(TimeStep);
end
end
hold off
end
I followed this code and video: Youtube

All my data for the plot is stored in a cell with multiple structs. Here is the example of one of these Structs, I desire to use only the data from the first column.

I have been trying to plot something like this for every iteration:

However, I am only being able to plot the first vector, can someone help me understand what I am missing on my code? My main difficulty is that the number of points change with the system that I try to simulate.
Thank you for all your help and attention.
Tiago
EDIT: Added a new code that is now able to plot the first iteration atleast.
Accepted Answer
More Answers (0)
Categories
Find more on Animation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


