import csv file with headers as variables name
2 次查看(过去 30 天)
显示 更早的评论
Hello,
I have a CSV file with first row containing column name, which is variable name.
I'd like to import this file so that the variables which would be created, would be the column name.
For example:
Student ID
Michael 56
Ashish 35
After importing, there would be 2 variables named Student and ID:
Student=[Michael Ashish]
ID=[56 35]
Additional issue is that the CSV file contains both text and numbers in the column.
Please assist.
Thank you :)
1 个评论
Stephen23
2016-5-19
"the variables which would be created"
It is a bad way to code to magically "poof" variables into existence. A much neater, faster, and more robust solution would be to simply use a table or to convert the data to a structure.
回答(1 个)
Walter Roberson
2016-5-18
You cannot do that with csvread(). You will need to use textscan() or readtable()
3 个评论
Walter Roberson
2016-5-18
textscan() and readtable() were not supported back then. You will need to use fopen() and read and parse the lines, perhaps using sscanf()
Your question is phrased much as if you are doing a homework assignment, but it would not seem to make sense to be doing a homework assignment with a version of MATLAB released 15 years ago.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Text Files 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!