Having issue using the command of readtable
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Hi folks,
I am using readtable command to read the colums ('timestamp', 'Record Type', 'Value') in the attached file.
rawTable=readtable(path) % where path is the locaton of file in my computer
However, when I read variable rawTable.timestamp, it gives me the values in datetime format. However, I want these values in cell array format {'dd:mm:yy HH:mm'}.
Anyhelp would be much appreciated. Thank you.
Note: In original file, I was having values in cell array format. When i edited the .csv file, then I was getting 'timestamp' valus in datetime format.
I tried using different tricks like
im=detectImportOptions(path, 'NumHeaderLines', 0);
im=setvartype(im, 1, 'char');
rawTable=readtable(path,im);
With this trick, I am getting time in string array but in different format e.g. {10/01/2020 10:20'}, {'10:01:20 10:20'}. I would like to have timestamp values in unique string array format {'dd:mm:yy HH:mm'}.
1 comentario
dpb
el 13 de Mayo de 2021
"I want these values in cell array format {'dd:mm:yy HH:mm'}. "
May I be so bold as to ask why would you want datetime data as cellstr instead of the natural datetime?
You can always generate the output format however you want it for whatever purpose besides using it as time; but you completely lose the ability to manipulate, search, calculate, plot, ... anything else in that form.
Some background on the application might help to understand...
You can, of course, use an import options object and specifiy the way you want each variable interpreted on input if you're adamant in going that route.
Respuestas (1)
Sahil Jain
el 11 de Ag. de 2021
According to my understanding of the question, you want to convert the ‘timestamp’ column of your table from datetime format to cell array format. The code below should help you achieve this.
rawTable = readtable('data.csv'); % read the table
cell_array = convertStringsToChars(cellstr(rawTable.Timestamp, 'dd:MM:yy HH:mm')); % convert datetime to char cell array
rawTable.Timestamp = cell_array; % add the cell array to the table
With this approach, you can format the timestamp string as you want by changing the 'dd:MM:yy HH:mm' string.
0 comentarios
Ver también
Categorías
Más información sobre Data Type Conversion en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!