First colum of CSV-imported table has "x___" added to its name
Show older comments
I have a bunch of automatically-generated CSV files with headers, which I'd like to import into Matlab as a table. I used code such as
T = readtable('d:\test.csv', 'readvariablenames', true);
However, even though the name of the CSV's first column is runNr, the first column in the Matlab table gets named "x___runNr"


This clearly has something to do with the CSV files being in a slightly format different from that expected by Matlab. For instance, if I manually change the name of that first cell in Excel to something else, then reopen the CSV, the cell contents are all merged into a cell, on every row.
Still, I am not sure what to do to fix this, since I cannot change the format of the CSVs.
Any help?
1 Comment
Star Strider
on 21 Oct 2019
It imports correctly for me in R2019b (Update 1):
T =
runNr repNr trialNr file
_____ _____ _______ ____________________
NaN NaN NaN {0×0 char }
NaN NaN NaN {0×0 char }
NaN NaN NaN {0×0 char }
1 1 1 {'stimuli/12C1.wav'}
(Posting only a relevant subset of the columns.)
Answers (1)
Jeremy Hughes
on 21 Oct 2019
2 votes
If you read the raw bytes using fopen/fread you can see the mark at the beginning.
8 Comments
Jeremy Hughes
on 21 Oct 2019
According to Star Strider, it can in 19b.
z8080
on 22 Oct 2019
Steven Lord
on 22 Oct 2019
I would check with whomever generated the file to learn if the process of generating those files and/or the software used to generate the files changed between the last time they were imported without the "x_" prefix and the first time they were imported with the prefix. It's possible they made a change that they thought would not affect you but it turns out to have affected you.
z8080
on 22 Oct 2019
Steven Lord
on 22 Oct 2019
You could post-process the imported table to change the variable name. Something like this should work, though I haven't tried it:
mytable.Properties.VariableNames{1} = ...
strrep(mytable.Properties.VariableNames{1}, 'x___', '');
z8080
on 22 Oct 2019
Categories
Find more on Spreadsheets in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!