Create a time table

5 views (last 30 days)
Hey guys, thanks in advance.
I have a program that reads samples from a hardware receiver. When it starts receiving I use:
fprintf('Start of LimeSDR\n');
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;
and stops receiving:
% Cleanup and shutdown by stopping the RX stream and having MATLAB delete the handle object.
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
But this only gives me a column with start time and the samples. How can I do this,
Thank you
Miguel Albuquerque
Miguel Albuquerque on 21 Jun 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');

Sign in to comment.

Accepted Answer

Ishaan Mehta
Ishaan Mehta on 25 Jun 2022
Edited: Ishaan Mehta on 25 Jun 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)];
% rename table columns
table1.Properties.VariableNames = ["time" "samples" "frequency"];
table2.Properties.VariableNames = ["time duration" "samples" "frequency"];
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 = 3×3 table
time duration samples frequency _____________ _______ _________ 00:00:02 100 10 00:00:04 100 10 00:00:06 100 10
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

More Answers (0)




Community Treasure Hunt

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

Start Hunting!

Translated by