Variables created in different formats
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Karel Starý
el 29 de Abr. de 2022
Comentada: Karel Starý
el 4 de Mayo de 2022
Hello all,
I have huge datasheet in .CSV format. I load it into the Matalb with readtable command.
Here you can see an example of some data I am using EDIT: Attached: https://drive.google.com/file/d/1ufomb934NVoFwRQDZ6s3upJQFVICsqLL/view?usp=sharing
Then i want to create a variable from the data set.
rate_qpsk = src_files{ii}{:,validatestring('LTE_Adv__Q_PCellDLQPSKRate',src_files{ii}.Properties.VariableNames)};
rate_16 = src_files{ii}{:,validatestring('LTE_Adv__Q_PCellDL16QAMRate',src_files{ii}.Properties.VariableNames)};
rate_64 = src_files{ii}{:,validatestring('LTE_Adv__Q_PCellDL64QAMRate',src_files{ii}.Properties.VariableNames)};
rate_128 = src_files{ii}{:,validatestring('LTE_Adv__Q_PCellDL256QAMRate',src_files{ii}.Properties.VariableNames);
Now, for some reason holf of teh variable are created as double and other half is created as cell array.
I woul just change the format but ...
Please advise why Matlab works for some of the columns differently than for others and how to avoid this situation.
Thanks for all the comments/help.
2 comentarios
Koula Lysi
el 29 de Abr. de 2022
I am new to Matlab. I went though a similar issue and solved the problem using the command table2array(cell2table(rate_64)). I am sure that they do exist better methods though.
Respuesta aceptada
Stephen23
el 29 de Abr. de 2022
Editada: Stephen23
el 29 de Abr. de 2022
Your file is not really a Comma-Separated Values (CSV) file, it actually uses a tab as the values delimiter and comma as the decimal radix character. So you need to tell READTABLE this when you import it. Because of confusion with rather unfortunate date formats you will also need to specify the date format to correctly import those dates as DATETIME. For example:
fnm = 'data.csv';
opt = detectImportOptions(fnm, 'Delimiter','\t', 'DecimalSeparator',',', 'VariableNamingRule','preserve');
opt = setvaropts(opt, 'Time', 'InputFormat','d/M/y H:m:s.SSS');
tbl = readtable(fnm, opt)
5 comentarios
Stephen23
el 3 de Mayo de 2022
Editada: Stephen23
el 3 de Mayo de 2022
The file "lte log.csv" uses a completey different file format: specifically it uses a comma delimiter (unlike your "data.csv" file which used tab delimiter) and also attempts to use the comma as the decimal separator. However it fails at this because in order to use a decimal comma it has to use double quotes around every single number with a decimal fraction, turning them all into quoted text.
That is an awful file format to work with.
Original file "data.csv" subset (tab delimiter):
New file "lte log.csv" subset (comma delimiter, and check out those double quoted numbers):
"I am using SW for extranting the data from DRM to CSV."
What kind of SW is that? Does it use your OS locale settings?
Well, in any case, you have so far uploaded two different files with two different formats: while it is possible to write code to handle multple file formats, doing so significantly complicates the code. I strongly recommend that you streamline your data pipeline to ensure that it only returns one file format.
Más respuestas (0)
Ver también
Categorías
Más información sobre Spreadsheets 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!