Create a time table
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
Eric Sofen
2022-6-21
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?
采纳的回答
Ishaan Mehta
2022-6-25
编辑:Ishaan Mehta
2022-6-25
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.
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
table2
table3
Hope it helps,
Ishaan Mehta
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Array Geometries and Analysis 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!