Timestamp char or cell into double matrix
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Colin Edgar
am 16 Nov. 2018
Kommentiert: Colin Edgar
am 16 Nov. 2018
I have a script to discover missing time periods in large data sets that begin with a Timestamp (TS). The TS is in form of "yyyy-mm-dd HHMM"
The script imports the data into a cell array C:
data = cell2mat(cellfun(@str2double,C,'UniformOutput',false));
but all the functions within work on double matrix variables. This includes the output matrix, which is fprint'd into a new file.
What I need to do is retain the original TS as a character-type column in the output matrix. Since the point of the script is to fill in holes and remove duplicates, I must apply the index which maps out the missing stuff to the TS.
I have a few different ways to get the TS, but none of them is adequate. I can:
TSdnum=datenum(TS_filtered)
TSnew = datestr(TSdnum,31)
This somehow generates a timestamp which is 1 minute off. For example 2015-03-15 15:15 comes out as 2015-03-15 15:16
I can get a character array out of the cell:
TSraw = cell2mat(C{1})
but I don't know how to put this into the final array. I have used cell2string(strsplit(.... before but don't see how this can work.
I think I can make a table, and use .Format, but again, how to get into my output matrix.
0 Kommentare
Akzeptierte Antwort
Steven Lord
am 16 Nov. 2018
The script imports the data into a cell array C:
Since from your comment on manhan ravi's answer the data is tabular in nature, consider using readtable to read the data from the file into a table array (importing the dates as datetime instead of plain text), table2timetable to convert the table into a timetable, and retime to make the times in the timetable regularly spaced. See the "Adjust Timetable by Inserting Missing Data Indicators" example on the retime function documentation page for an example that sounds similar to the application you described.
Alternately, since you already have the data in a cell array you could use cell2table instead of readtable to convert the already-imported data to a table. After that convert the text representing the dates and times in the first variable in the table into datetime using the datetime function. Finally continue as above with table2timetable and retime.
Weitere Antworten (1)
Siehe auch
Kategorien
Mehr zu Timetables finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!