Variables created in different formats

4 views (last 30 days)
Karel Starý
Karel Starý on 29 Apr 2022
Commented: Karel Starý on 4 May 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 Comments
Karel Starý
Karel Starý on 3 May 2022
Thanks for hint.
Unfortunately this approach givs me same error as changing the format for the variable only -> Conversion to double from cell is not possible.
Still good try.

Sign in to comment.

Accepted Answer

Stephen23
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)
tbl = 816×5 table
Time LTE(Adv)-Q_PCell DL QPSK Rate LTE(Adv)-Q_PCell DL 16QAM Rate LTE(Adv)-Q_PCell DL 64QAM Rate LTE(Adv)-Q_PCell DL 256QAM Rate _____________________ _____________________________ ______________________________ ______________________________ _______________________________ 2/5/2022 11:35:21.000 NaN NaN NaN NaN 2/5/2022 11:35:22.000 0 0 15.22 84.78 2/5/2022 11:35:23.000 0 0 69.57 30.43 2/5/2022 11:35:24.000 0 0 4.35 95.65 2/5/2022 11:35:25.000 0 0 0 100 2/5/2022 11:35:26.000 0 0 0 100 2/5/2022 11:35:27.000 0 0 0 100 2/5/2022 11:35:28.000 0 0 2.17 97.83 2/5/2022 11:35:29.000 0 0 23.91 76.09 2/5/2022 11:35:30.000 0 0 95.65 4.35 2/5/2022 11:35:31.000 0 0 19.57 80.43 2/5/2022 11:35:32.000 0 0 0 100 2/5/2022 11:35:33.000 0 0 45.65 54.35 2/5/2022 11:35:34.000 0 0 10.87 89.13 2/5/2022 11:35:35.000 0 0 30.43 69.57 2/5/2022 11:35:36.000 0 0 0 100
  5 Comments
Karel Starý
Karel Starý on 4 May 2022
Thanks. I really apprechiated this help.

Sign in to comment.

More Answers (0)

Products


Release

R2022a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!