Matlab continuous plotting - most optimal way to do it (mine approach is so uneffective!)
10 views (last 30 days)
Show older comments
Hello everybody!
I wil ltry to be brief as i can.
I have a certain external embedded device that sends data over serial socket (to be specific it is 26 float values in format x.xxxx, sapce separated, end of "chunk" is marked by EOL character).
In my script i am storing those values into predefined arrays plus i am printing 16 of them into plot figure. I am printing it point by point and only for the first set of points i allow legend and for all the other points i am supressing the legend (turning off). This way i have nice real time graph with legend.
Data come every 200ms (5 sets per second). The problem occures, after i am plotting for more then (approximately) 200 seconds. That means there is already 200*5*16 points and after that time adding a new sets into graph is becomming so time consuming for the PC, that the data reception on the serial line start pile in the input buffer (i guess). After some time i reach the point, where the buffer is filled (i guess, thats only a hypothesis) and newcoming sets of data gets lost.
EDIT: I want to point out that i am casting drawnow; to refresh the plot. Is that a correct way how to do it?
I have there in my code a mechanism that take care of "uncompleted corrupted sets of data" because i was expecting that the serial communication can gets corrupted sometimes and i didnt want to have that corrupted data in my plots. Problem is that when i reach that point when updating my plot with new sets become so freaking time consuming, this data loss happen too frequent!
I have also a mechanism, that partly solves this issue by not plotting all the date into one plot, but rather only displeing a "window of time" like 100 seconds and after reaching 100 seconds closing the figure and opening new blank. But i would like to extend the size of the time exis so i can display more data without getting bugged.
FINALLY MY QUESTION IS:
Is there a better way how to perform a real time graph plotting? Something like adding a new points to a existing line (that would also avoid problem with legenda displaying for each point instead of line). Is this even more otimal (this adding to existing line method)?
0 Comments
Answers (1)
See Also
Categories
Find more on Legend 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!