Split cvs on commas but prevent doing so for a string with a comma in it

16 visualizaciones (últimos 30 días)
My Excel csv file looks like this:
Data,test,04-12-2020 13:11,0,"8,2",1,2,3
Currently I use the following code to seperate the columns:
[~,~,dataCGM] = xlsread('file.csv');
outCGM = regexp(dataCGM, ',', 'split');
outCGM = outCGM(2:end-1);
This does split the columns on commas but also does so for the string "8,2" which is not what I want. Does anyone know how to prevent this issue and keep the value as a string in a single column?

Respuestas (2)

Cris LaPierre
Cris LaPierre el 13 de Dic. de 2020
Perhaps one of the options given here is helpful.
  20 comentarios
Cris LaPierre
Cris LaPierre el 14 de Dic. de 2020
I can only make it work for what I see.
You can look into what settings are available from detectImportOptions. I suspect the NumHeaderLines is what you are looking for.

Iniciar sesión para comentar.


Walter Roberson
Walter Roberson el 13 de Dic. de 2020
readtable() with a format that is
'%s,%s,%{dd-MM-uuuu HH:mm}D,%f,%q,%f,%f,%f'
  2 comentarios
Image Analyst
Image Analyst el 13 de Dic. de 2020
That makes no sense. A program will not "work on itself". You need to tell your code HOW to process the file. It won't magically figure it out. Attach your csv file if you need more help.

Iniciar sesión para comentar.

Productos


Versión

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by