Real time growing table. Should I use table, double array, cell array..?

3 Ansichten (letzte 30 Tage)
Javier Mateo
Javier Mateo am 18 Jan. 2021
Kommentiert: Javier Mateo am 19 Jan. 2021
I am reading data from a serialport using Callback.
So every line of data is a 'double 1x3' like:
new_line = [time distance RSSI]
Every second I get around 6-8 lines and I need to store them and plot in real time ( plot(time,distance) )
It can be easily done with matrix like:
M(end+1,:)=new_line
However, I have to separate into 8 different matrix because the data is gathered from different sources. One easy way is to make 8 different matrix (M1, M2... M8)
But I wonder if I can store all in the same variable (a table)? The goal would be something looking like this:
T =
8×2 table
M1 M2
_____________________________ _____________________________
0.20619 249 -35 0.53786 257 -35
1.214 249 -35 1.5412 238 -35
2.2208 221 -35 2.537 235 -35
3.2199 262 -35 3.5289 268 -35
4.2186 240 -35 4.5363 226 -35
5.2124 252 -35 5.557 244 -35
6.2206 226 -35 6.5375 230 -35
7.2237 242 -35 7.5445 230 -35
But for 8 different variables, and increasing rows (size not known before hand)
But then, how do I store every new line of data in the specific "source" column, without affecting the other sources column? Am I in the wrong direction?
Thank you very much in advance
  8 Kommentare
Stephen23
Stephen23 am 18 Jan. 2021
Bearbeitet: Stephen23 am 18 Jan. 2021
"What is "a lot of data" when we talk about programming?"
I would say "when it gets close to the size of your available memory".
"I use global variable because this function is called by callback, so I guess there is no other way"
Gobal variables are not a reliable or efficient way to pass data between callbacks (or for that matter between any functions). Global variables are avoided by experienced programmers because their usage wastes programming and debugging time.
The recommended approaches are given here:
You might find this useful too:
Javier Mateo
Javier Mateo am 19 Jan. 2021
Thank you very much for the recommendations.
I will consider about that if the programm becomes greater. For now it seems to be working flawless with globals.

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by