Im new to matlab coding so im still trying to get my head around things. Pretty much im working with interia sensors which output the sensors orientation data every 10ms. Im able to store this data into a text file which is continuously updating.
My task now is to plot this data in real time. This involves continuously accessing and reading from the text file (every 10ms if possible) and graph this data with respect to time. Can any of you guys give me some guidance onto what would be the most effective way to do this.
At this moment in time, the text file only stores data about one parameter (the x coordinate of the sensor). I can store this data in 2 way: Method 1: New data every 10ms. Each is stored in a new line. Method 2: I can make the text file only have the most recent piece of data (erasing previous data) Im able to use either of these methods.. whatever you guys think would be easier.
Ive tried using other 3rd party software to graph this data from the text file, but they all seemed really jumpy and couldnt read from the text file fast enough.
Thanks.
A MATLAB timer object will help. See, for example, this link Using MATLAB to process files in real-time after every instance a file is created by a separate program.
There may be some worry regarding the simultaneous write (your other process) and read (MATLAB) to a single file. Your situation may be more suited to a pipe rather than a file: Pipe vs. Temporary File but I will proceed with a MATLAB based solution for timed file reads and plot updates.
I emulated your situation and learned a few things:
fread
is made. See the work arounds usingfseek
in thereadFile
function below.fobj = open('test.dat', 'wb', 0)
.MATLAB code below:
Python code to write data to a file every ~ 10 milliseconds: