read csv file: variable name consists of multiple words: resulting table variable name
2 views (last 30 days)
Show older comments
alpedhuez
on 24 Jan 2021
Commented: Walter Roberson
on 24 Jan 2021
I readtable a csv file of the format
date new york
---------------------
1/1/2021 15
1/2/2021 20
Then the resulting table has
class_Var1 class_NewYork
----------------------------
datetime double
But I just want to have a variable name 'New York'. Is it possible?
0 Comments
Accepted Answer
Nolan Canegallo
on 24 Jan 2021
Edited: Nolan Canegallo
on 24 Jan 2021
If you have R2020b+, then you can use a modifier:
tableName = readtable('filename.csv','VariableNamingRule','preserve')
If you have R2019b+, then you can use the modifier:
tablename = readtable('filename.csv','preservevariablenames',true)
Credit to Walter Roberson for noticing this typo in the documentatation.
6 Comments
Nolan Canegallo
on 24 Jan 2021
Edited: Nolan Canegallo
on 24 Jan 2021
I agree that it is easy enough to check, however, it does not mention the correct date in the section with the flag. I think including R2019b in this section is misleading, since it implies that this flag is compatible with R2019b.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/498827/image.png)
Walter Roberson
on 24 Jan 2021
Again, you are assuming that the "Starting in R2019b" applies to the whole paragraph, but it does not.
Consider "Starting in 1979, I no longer lived in the house I grew up in. I live in central Canada." Does that mean that I have lived in central Canada all of my life? Does that mean that I have lived in central Canada since 1979? Does the second sentance somehow become incorrect when you know that I have lived in central Canada since the early 1990s, and if so where is the error, since both parts are individually true?
More Answers (0)
See Also
Categories
Find more on Logical 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!