import csv file with headers as variables name

조회 수: 7 (최근 30일)
michael
michael 2016년 5월 18일
댓글: Stephen23 2016년 5월 19일
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
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
Walter Roberson 2016년 5월 18일
You cannot do that with csvread(). You will need to use textscan() or readtable()
  댓글 수: 3
Walter Roberson
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.
michael
michael 2016년 5월 18일
편집: michael 2016년 5월 19일
This is one of the versions in my work. I have 15a but also 6.5 which is more available for me

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Text Data Preparation에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by