Variables created in different formats
4 views (last 30 days)
Show older comments
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.
Accepted Answer
Stephen23
on 29 Apr 2022
Edited: Stephen23
on 29 Apr 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)
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!