How do I generate a frame by frame animation?
17 views (last 30 days)
Show older comments
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
Answers (0)
See Also
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!