Matlab animation for x y plot that is updated based on timestamps

I have collected x & y data with a sensor and have associated each x,y point pairing with the timestamp in which they were collected. I would like to make an animated plot in MATLAB which plots the x,y points according to these timestamps so that the resulting video file plays back with xy plot being generated according to when the points were collected by the sensor. What is the best way of coding this?

5 Comments

Look at the animatedline examples for starters, maybe...
Thanks for the suggestions, but I am not so much concerned about making the or saving to file. I am more focused on figuring out how to get the plot to be generated according to the vector of timestamps.
Here is a more detailed example of what. Lets say in my data I have many points of x,y positions and each position is associated with timestamp of when it was recorded. Hypothetically, lets say two of these points are an x,y position of (+3, -4) with an associated timestamp of 3.23 seconds (point a) and an x,y position of (+5, -4) with an associated timestamp of 3.45 seconds (point b). What I want to be able to do is ultimately create a video file with MATLAB that I can play back on a different media player (for example VLC). Then when I play back the video I want to be to see that at 3.23 seconds a new point at x,y location (+3, -4) has been added to plot, and that at 3.45 seconds into the video I see that a new point at x,y location (+5, -4) has been added to the plot.
What I am trying to find out, is that when you are using animatedline or any other MATLAB function that can be used to make a video file from a plot, how can you dictate the specific time certain parts of the plot are generated?
I've never messed with trying to build movies but the movie command to play a movie has an optional input variable, fps or frames/second.
It looks like you would have to build the movie with as many repitions of the preceding frame as the difference in times at the chosen frame rate to actually synchronize time events in that manner.
Other than that, all I can think of would be to use a timer that was a one-shot that reset the next time increment to trigger a callback function that reads/displays the next image in sequence. That won't be terribly accurate, but in the ballpark, I'd guess.
I think I might have an answer - I had a similar problem. I have data from mechanical testing in three columns: 1. time since start in seconds (starting from 0.0), 2. extension of the testing arm, and 3. the load excerted on the sample. I need to see how load changes in time as the testing arm is moving. The problem I had was that I have stops on the way based on external factors and it makes timestamping not constant (I do not have linear progression 0,0.1,0.2 and so on). I have approached it like this and it seems to be working:
%the data is imported manually here.
t = data(:,1); %time column
x = data(:,2); %arm extension column
y = data(:,3); %load column
hold on
p_1 = plot(x(1),y(1),'color',[1,0,0],'linewidth',2);
grid on
for k = 2:length(x-1)
set(p_1,'xdata',x(1:k),'ydata',y(1:k));
pause(t(k+1)-t(k));
end

Sign in to comment.

Answers (1)

Read about comet3.
If you want to save it as an animation, consider writing it into a gif file. You can refer this for writitng into gif file:
To plot in a loop use:
Let (t,x,y) be your data.
nt = length(t) ;
for i = 1:n
plot3(t(1:i),x(1:i),y(1:i))
drawnow
end

Categories

Products

Release

R2020b

Asked:

on 25 Jun 2021

Commented:

on 19 Oct 2021

Community Treasure Hunt

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

Start Hunting!