필터 지우기
필터 지우기

How to import data with column headings?

조회 수: 40 (최근 30일)
Hydro
Hydro 2017년 12월 24일
댓글: Hydro 2017년 12월 24일
Hello all, attached is a sample of my data. I would like to import the data as a matrix, when I do so, I lose column headings. Importing data as a table will work (see attached), however, I don't want my data to be in table form. I want my data in a matrix with top row as column headings as it is in csv sheet. Any thought would be appreciated. I tried to convert the table into array (table2array) but I lose column heading again.

채택된 답변

Image Analyst
Image Analyst 2017년 12월 24일
This works for me:
[~, ~, data] = xlsread('data.csv')
What happened when you tried it?
  댓글 수: 2
Hydro
Hydro 2017년 12월 24일
Hello @Image Analyst.
your code gives me cell, which i dont want. i used cell2mat but didnt work as the data type is not same.
Image Analyst
Image Analyst 2017년 12월 24일
Like Walter says in his answer, that's not possible. You can either do a cell array, like I showed you, or use a table, like you've already done. I suggest you use a table. Tables are great and you'd do yourself a favor to get used to them.

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

추가 답변 (1개)

Walter Roberson
Walter Roberson 2017년 12월 24일
In MATLAB, it is not possible to have a header on a numeric matrix. If you want to preserve the headers, you have two options:
  1. import as a cell array with each entry being in a different cell; or
  2. import as a table and use the table VariableDescriptions property to store the headers (note: the variable descriptions only show up if you use summary() or ask for them specifically.)
  댓글 수: 1
Hydro
Hydro 2017년 12월 24일
Hello Walter/Image Analyst, I agree. Actually, I am trying to construct a timetable, which I would use for further analysis. I don't use table often-so I am bit uncomfortable. I construct the timetable but importing data as vector and then adding vector one by one while constructing the time table. Since I have more column, thought there would be an easy way of doing this.
Walter! Part of the code is yours.
StartDate = datetime(2011,01,01);
EndDate = datetime(2011,12,31);
Date = (StartDate:calmonths(1):EndDate)';
Date.Format = 'MMM-yyyy';
TT=timetable(Date,RCP45_2030s_W0_Removed,RCP45_2030s_W25_Removed,RCP45_2030s_W50_Removed,RCP45_2030s_W75_Removed,RCP45_2030s_W100_Removed);

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

카테고리

Help CenterFile Exchange에서 Data Import and Analysis에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by