필터 지우기
필터 지우기

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

조회 수: 4 (최근 30일)
Javier Mateo
Javier Mateo 2021년 1월 18일
댓글: Javier Mateo 2021년 1월 19일
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
Stephen23
Stephen23 2021년 1월 18일
편집: Stephen23 2021년 1월 18일
"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 2021년 1월 19일
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.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Serial and USB Communication에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by