For real systems or simulation platforms, data is generated incrementally. Matlab in addition to powerful matrix operations, but also has a powerful data visualization library. Because there are many static drawing methods, this paper only focuses on the dynamic display of incremental data flow. ** This paper mainly introduces several Matlab data dynamic display methods. There are two main methods of ** :

  • hold on
  • Combine the set function with the drawnow function

Hold on method

1. Method introduction

This method is relatively primitive and suitable for real-time data. The principle is to draw a frame first, then retain the original image and add the next image. This method is cumbersome and involves drawing details, and there is no complete and continuous Line object data. One caveat to this method is that if you want to generate a continuous plot, you should have at least two points per plot. If you want to draw increments one point at a time, select ‘.’ for linestyle.

2. Codes and legends

t=0; T1 = 0.1 [0]; % if '-', enter at least two dots at the same time. '.' does not use m1=sin(t1); p = plot(t1,m1,'-b','MarkerSize',5); X = 1.5 * PI; Axis ([x x + 2 * PI - 1.5 1.5]). grid on; For I =1:1000 hold on t=0.1* I; % next point t1=t1+0.1; % next line m1=sin(t1); p = plot(t1,m1,'-b','MarkerSize',5); X = x + 0.1; Axis ([x x + 2 * PI - 1.5 1.5]). Pause (0.01); endCopy the code

Combine the set function with the drawnow function

1. Method introduction

This mode is more suitable for drawing animation, with high efficiency, small refresh and flicker, suitable for real-time data, and the final Line structure data is complete. Before understanding this method, it is necessary to understand the prototype of Plot function: each Plot is maintained by a handle, and the corresponding Plot parameters of the handle can be updated online by the set function. If the data of Plot is updated online, the effect of dynamic display can be realized. Finally, the plot is refreshed using the drawnow function.

2. Codes and legends

t=[0] m=sin(t) p = plot(t,m,'EraseMode','background','MarkerSize',5); X = 1.5 * PI; Axis ([x x + 2 * PI - 1.5 1.5]). grid on; For I = 1 00 t = 0.1 * I] [t; M = sin (0.1 * I) [m]. Set (p, 'XData' t, 'YData' m) drawnow x = x + 0.1; Axis ([x x + 2 * PI - 1.5 1.5]). Pause (0.01); endCopy the code

conclusion

This paper introduces two methods to realize real-time data visualization. That’s what it looks like in motion. The principle of the two methods and the example program and legend are presented respectively. You can use these two simple examples to create colorful data visualizations.