Matlab Coordinate chart animation, dynamic display of data

Source: Internet
Author: User

Data collection or playback, using MATLAB plot to draw the words are generally static, after the painting is not moving. However, in some cases, such as real-time data acquisition and then through the serial port or PCI in MATLAB to draw the data of the change diagram and synchronous dynamic display, as well as some want to use MATLAB drawing back to enlarge the block of data simulation over time scenarios. At this point, we need to use the coordinates of the animation display. This feature is implemented in a variety of ways, only one of the simplest is the recommended use of MATLAB.

The implementation of this feature relies on the Animatedline object, with the use of the Drawnow function, the specific use can see Help, the following is also briefly described below, are the help document for handling.

1: Basic implementation

h = animateline;
Axis ([0,4*pi,-1,1])
x = Linspace (0,4*pi,1000); y = sin (x); for k = 1:length (x) addpoints (H,x (k), Y (k)); Drawnowend

If there is another function that wants to get data from the current graph, use the Animateline getpoints method

[Xdata,ydata] = getpoints (h);

2: If you want to achieve the effect of the snake, the dynamic image is only part of the display, not every time you start from the beginning to display, you can set the maximum number of paint, by setting the value of maximumnumpoints this property to achieve

h = animatedline (' maximumnumpoints ', +), axis ([0,4*pi,-1,1]) x = Linspace (0,4*pi,1000); y = sin (x); for k = 1:length (x)    addpoints (H,x (k), Y (k));    Drawnowend

3: Speed up the skills of the refresh, the above each loop only to add a point to the structure, the real-time display of the words may not be able to keep up with the speed, so you can consider a loop to add multiple points inside, so that you can speed up the refresh

h = Animatedline;axis ([0,4*pi,-1,1]) numpoints = 100000;x = Linspace (0,4*pi,numpoints); y = sin (x); for k = 1:100:numpoints-    Xvec = x (k:k+99);    Yvec = y (k:k+99);    Addpoints (H,xvec,yvec)    drawnowend

4: can also speed up animation with Drawnow update

h = Animatedline;axis ([0,4*pi,-1,1]) numpoints = 100000;x = Linspace (0,4*pi,numpoints); y = sin (x); for k = 1:numpoints    Addpoints (H,x (k), Y (k))    Drawnow Updateend

5: Control the speed of animation, and sometimes, hope that the animation shows a little slower, the above is to speed up the animation, if you want to control the animation speed, you can match tic function and TOC function, equivalent to a record program run stopwatch, call tic means click to start the timing, call the TOC to stop the time, The time difference between the two is the duration of the program, and the following code indicates that the control frame speed is 30

h = Animatedline;axis ([0,4*pi,-1,1]) numpoints = 10000;x = Linspace (0,4*pi,numpoints); y = sin (x); a = tic;  % start timerfor k = 1:numpoints    addpoints (h,x (k), Y (k))    B = TOC (a);% Check timer    if B > (1/30)        Drawnow % Update screen every 1/30 seconds        a = tic,% reset timer after updating    Endenddrawnow% Draw final frame

Other details, such as setting the line properties, can be seen in the Help document

 

  

  

  

Matlab Coordinate chart animation, dynamic display of data

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.