Convert CSV into Multiple 1-D Arrays

조회 수: 21 (최근 30일)
Justin Kuo
Justin Kuo 2021년 3월 17일
댓글: Star Strider 2021년 3월 17일
I have a spreadsheet saved as a .csv. The first row is headers and the remaining are data. I want to read this file and create an array for each column and the name of each array should be the header (the string in the first row of that column). The data is 159 columns by 9591 rows and I have multiple sheets so I'd like for the arrays in MATLAB to name themselves.
For example, if my spreadsheet looks like:
Name Birthday Age
Alex January 1 30
Bob February 1 35
Charlie March 1 40
I would want for MATLAB to generate three arrays. One named "Name" that has the values "Alex", "Bob", and "Charlie", one named "Birthday" that has the values "January 1", "February 1", and "March 1" and one named "Age" with values "30", "35", and "40". My actual data is all numbers.
Any suggestions"

채택된 답변

Star Strider
Star Strider 2021년 3월 17일
If you have R2013b or later, use the readtable funciton. It should do everything you want. You can create separate tables for each variable if you want to do that. (I would not recommend it, however. It would be best to just keep everything in the original table.)
  댓글 수: 2
Justin Kuo
Justin Kuo 2021년 3월 17일
I see. Thank you. It's been a few years since I've used MATLAB and I didn't use tables much back then.
Star Strider
Star Strider 2021년 3월 17일
As always, my pleasure!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Spreadsheets에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by