Problems with splitting with readtable

13 views (last 30 days)
Eleen
Eleen on 11 Dec 2023
Moved: Cris LaPierre on 11 Dec 2023
Hi all,
I have a question regarding the readtable-function. I want to use this function to import a .csv-file into a table, but I'm having some problems with correclty splitting the data from this file. I added an example file of the file I want to import. The variable names of the table that I want to create, are in row 3 and the data are in row 4-6. By using the readtable function and specifying 'NumHeaderLines', I can correclty split the variable names. However, it does not correctly split the data, even when I'm using the 'Delimiter' option. All the data always ends up in the first column, but that is not how I want it. In the first data row ,the data from the variable 'Apparaat' should ABC DEF, from 'Serienummer' ABC123-ABC123-ABC123-ABC123-ABC123, from 'Tijdstempel apparaat' 24-07-2022 02:18, from 'Gegevenstype' 0, from 'Historische glucose mmol/l "6.0" and all the others columns should be empty. It does not matter that much what kind of datatypes are in the table, I can change them afterwards.
Does anyone know or has any tips how I can correctly split the data?
Thanks a lot!
  1 Comment
Mathieu NOE
Mathieu NOE on 11 Dec 2023
seems the old csvimport is better handling your csv file
out = csvimport('Examplefile.csv');
out = 6×5 cell array
{'Patiëntrapport'} {'Gegenereerd op' } {'07-12-2023 13:29…'} {'Gegenereerd door'} {'Eleen Schupp' }
{'Examplefile' } {0×0 char } {0×0 char } {0×0 char } {0×0 char }
{'Apparaat' } {'Serienummer' } {'Tijdstempel appa…'} {'Gegevenstype' } {'Historische gluc…'}
{'"ABC DEF' } {'ABC123-ABC123-AB…'} {'24-07-2022 02:18' } {'0' } {'""6' }
{'"DEF GHI' } {'ABC123-ABC123-AB…'} {'24-07-2022 02:33' } {'0' } {'""7' }
{'"GHI ' } {'ABC123-ABC123-AB…'} {'24-07-2022 02:48' } {'0' } {'""8' }

Sign in to comment.

Answers (1)

Eleen
Eleen on 11 Dec 2023
Moved: Cris LaPierre on 11 Dec 2023

Categories

Find more on Tables in Help Center and File Exchange

Products


Release

R2022a

Community Treasure Hunt

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

Start Hunting!