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

44 views (last 30 days)
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
dpb
dpb on 28 Jun 2021
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.
Jacek Olender
Jacek Olender on 19 Oct 2021
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)

KSSV
KSSV on 28 Jun 2021
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

Find more on Animation in Help Center and File Exchange

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!