Variables created in different formats
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
Koula Lysi
2022-4-29
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.
采纳的回答
Stephen23
2022-4-29
编辑:Stephen23
2022-4-29
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 个评论
Stephen23
2022-5-3
编辑:Stephen23
2022-5-3
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.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Spreadsheets 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!