How do I generate a frame by frame animation?

17 views (last 30 days)
I want to create a frame by frame representation of data I collected and processed into MATLAB and am trying to figure out how to plot it and fix the axes in order to get a good visual representation of what happened in real space
One set of data gives me the x,y,z points of each frame and I want to be able to visualize this. This is what I have right now for that:
for i=1:length(LiDARpc) %run throught the n frames we have. could do for length(WStimes) if we have full set
scatter3(LiDARpc{i,1}(:,7),LiDARpc{i,1}(:,8),LiDARpc{i,1}(:,9),'.') %plots x,y point of each point in this
axis equal
pause(0.1);
end
In the above LiDARpc is a cell array where each cell has a matrix with each column representing a measured variable (7 is x position, 8 is y position and 9 is z position) and each row is a point inside that frame. This works decent enough for my needs but Im not sure fi there is a better way to code this or something else that may give me more capabilities. Ideally I want to be able to fix the axes beforehand and so they arent constantly updating each frame.
The other one I want to plot is a point and the direction it is pointing at each frame. Ideally for this one I want to have a circle that has an arrow point in the direction it is pointing (based on my 0->360 degree angle measurement) but also leave a line behind it that shows where it has been. This one I just need 2D data right now in the xz plane because y will be a constant for my experiments (in this view we have a y-up cooridnate system). I have the position and angle histories for this but am not sure best way to plot it
h = animatedline;
axis([min(OPTITRACKpc(:,6))-1 max(OPTITRACKpc(:,6))+1 min(OPTITRACKpc(:,4))-1 max(OPTITRACKpc(:,4))+1])
for k = 1:length(OPTITRACKpc)
addpoints(h,OPTITRACKpc(k,6),OPTITRACKpc(k,4));
drawnow
end
The above right now gives me the line that I want but I am not sure how to represent the arrow. I also ideally would want to have an open circle be moving on the line so that in the future when I have an object moving along the same path over and over I can see where it is along the path. Think as though the first time aroubnd it draws a circle and then after that you can see an open circle moving along that path.
  2 Comments
Star Strider
Star Strider on 4 Feb 2020
I’m not certain what your code does.
See if the getframe function (and its friends) will do what you want.
bryan bergan
bryan bergan on 4 Feb 2020
The one that I care more about is the second lines of code I listed. Essentially I have the 2D position of a "car" with a heading direction (some angle from 0 to 360 degrees). I have vectors for each of these 3 variables (2 for the position, 1 for the direction) all of the same length where each entry in each vector is occuring at the same time.
I want to represent the cars current location as a small circle, its current orientation as an arrow pointing from said circle, and I want to have a line that is plotting the path of the car as it progresses through the frames.

Sign in to comment.

Answers (0)

Categories

Find more on Animation in Help Center and File Exchange

Products


Release

R2019b

Community Treasure Hunt

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

Start Hunting!