Borrar filtros
Borrar filtros

Create a time table

10 visualizaciones (últimos 30 días)
Miguel Albuquerque
Miguel Albuquerque el 21 de Jun. de 2022
Editada: Ishaan Mehta el 25 de Jun. de 2022
Hey guys, thanks in advance.
I have a program that reads samples from a hardware receiver. When it starts receiving I use:
dev.start();
fprintf('Start of LimeSDR\n');
tic;
start_time=datestr(now);
Then it receives this samples:
indRx1 = 1; % index of the last received sample
[samples1, ~, samplesLength1] = dev.receive(Fs*Ts,1);
bufferRx1(indRx1:indRx1+samplesLength1-1) = samples1;
pause(1)
tempo_rececao=toc;
stop_time=datestr(now);
and stops receiving:
% Cleanup and shutdown by stopping the RX stream and having MATLAB delete the handle object.
dev.stop();
clear dev;
fprintf('Stop of LimeSDR\n');
I want to create a timetable that has start time, stop time, Fs(frequency sampling), and samples1(number of samples).
I have done this
TT=array2timetable(samples1,'SampleRate',Fs,'StartTime',start_time);
But this only gives me a column with start time and the samples. How can I do this,
Thank you
  2 comentarios
Eric Sofen
Eric Sofen el 21 de Jun. de 2022
Timetable works with datetime and duration data types, but not datestr, so your start_time and stop_time should be:
start_time = datetime("now");
I'm unclear on your question. Do you want separate variables in the timetable for start_time and stop_time? What is the height of samples1? Are you ending up a one-row timetable in TT?
Miguel Albuquerque
Miguel Albuquerque el 21 de Jun. de 2022
I would like that the table, had one one column the time( start_time :stop_time), then on another column the samples 1, I made the test and I was getting 2 columns. The first one with time had the start_time but ended up in a time different from stop time, and on another column I had the samples( 100000 samples).
I changed start_time and stop_time to this:
start_time=datetime('now','Format','dd-MMM-uuuu HH:mm:ss.SSS');
stop_time=datetime('now','Format','dd-MMM-uuuu HH:mm:ss.SSS');

Iniciar sesión para comentar.

Respuesta aceptada

Ishaan Mehta
Ishaan Mehta el 25 de Jun. de 2022
Editada: Ishaan Mehta el 25 de Jun. de 2022
Hi Miguel
From your last comment, as per my understanding, you want to record start_time and end_time in the same column, and then samples1 and fs in other columns in a timetable.
A timetable is a MATLAB datatype which associates a timestamp with each of the rows stored in it.
Please have a look at MATLAB timetable datatype documentation.
According to me, you can go for the table datatype for a single column storing both the start_time and end_time.
For using timetable datatype, the start_time and end_time must be in different columns.
Incase you want to store the time-duration between start_time and stop_time in the first column, that can be done by subtracting start_time from the end_time as demonstrated in the code below.
You can use the following code as a reference.
table1 = table; % table with start_time and end_time in same column
table2 = table; % table with time-duration in first column
table3 = table; % table with start_time and end_time in separate columns
for i = 1:3
fs = 10; % dummy fs
samples1 = 100; % dummy samples1
start_time = datetime('now');
stop_time = datetime('now') + seconds(i*2); % dummy stop_time
% Variables above are initialised to dummy values for demonstration.
% You should get all the variables above from your own program only,
% before the following code is executed
nRows = height(table2);
table1 = [table1; table(string(start_time) + " : " + string(stop_time), samples1, fs)];
table2 = [table2; table(stop_time - start_time, samples1, fs)];
table3 = [table3; table(start_time, stop_time, samples1, fs)];
end
% rename table columns
table1.Properties.VariableNames = ["time" "samples" "frequency"];
table2.Properties.VariableNames = ["time duration" "samples" "frequency"];
table1
table1 = 3×3 table
time samples frequency _____________________________________________ _______ _________ "25-Jun-2022 15:13:39 : 25-Jun-2022 15:13:41" 100 10 "25-Jun-2022 15:13:39 : 25-Jun-2022 15:13:43" 100 10 "25-Jun-2022 15:13:39 : 25-Jun-2022 15:13:45" 100 10
table2
table2 = 3×3 table
time duration samples frequency _____________ _______ _________ 00:00:02 100 10 00:00:04 100 10 00:00:06 100 10
table3
table3 = 3×4 table
start_time stop_time samples1 fs ____________________ ____________________ ________ __ 25-Jun-2022 15:13:39 25-Jun-2022 15:13:41 100 10 25-Jun-2022 15:13:39 25-Jun-2022 15:13:43 100 10 25-Jun-2022 15:13:39 25-Jun-2022 15:13:45 100 10
Hope it helps,
Ishaan Mehta

Más respuestas (0)

Categorías

Más información sobre Tables en Help Center y File Exchange.

Productos


Versión

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by