Remove quotes in last column of my table

Hi,
Atm, I'm reading a big dataset in ML by:
DATA = readtable('data_log_gyro.csv');
Example below
Now I want the third column also in numerical values (so one column split into three columns) instead of in between quotes, I reached out to
opts = detectImportOptions('data_log_gyro.csv');
I tried changing the 'Variable type' to double, but then it's output is NaN
varTypes = {'categorical','datetime','double'};
opts = setvartype(opts,varTypes);
But was unable to find the correct options for this. Anyone who has a clue?

 Accepted Answer

You can use the Format option in readtable with a format of
"%{yyyy-MM-dd}D %{dd-MMM-yyyy}D %{hh:mm}T ('%f', '%f', '%f')"
Note that I used double-quotes for the format, so that I would not have to escape the ' characters which are to appear literally.
There are other approaches, using the detected import options and modifying the Prefix and Suffix properties.

5 Comments

Thanks for your fast response, appreciate it!
Hmm does not seem to work still.
Dataset changed a bit (see time), but that shouldn't be much of an issue I suppose. I changed it to below.
settings= "%{yyyy-MM-dd}D %{hh:mm}T ('%f', '%f', '%f')"
GYRO_DATA = readtable('data_log_gyro.csv','Format',settings)
Also tried this
settings= '%{yyyy-MM-dd}D %{hh:mm:ss}T %('%f', '%f', '%f')'
But this induces errors 'unable to parse the format character...'
It would be easier on us if you provided a sample text file, instead of providing a picture of a text file.
Any follow up ideas on this problem?
Any follow up ideas on this problem?
Unfortunately, due to social isolation, my sleepless clones have recently not been able to take over for me while I power down for maintenance.
filename = 'Sample.csv';
settings = "%{yyyy-MM-dd}D %{hh:mm:ss}T ""('%f' '%f' '%f')""";
T = readtable(filename, 'Format', settings, 'readVariableNames', false, 'HeaderLines', 0, 'Delimiter',',');
dates = T.Var1 + T.Var2;
num1 = T.Var3;
num2 = T.Var4;
num3 = T.Var5;
This is fantastic, Thanks a lot! Spend a whole day trying to figure this out yesterday.

Sign in to comment.

More Answers (0)

Products

Release

R2019a

Community Treasure Hunt

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

Start Hunting!