readtable and table2array

28 ビュー (過去 30 日間)
Chet Sharma
Chet Sharma 2018 年 3 月 11 日
回答済み: Peter Perkins 2018 年 3 月 15 日
Hi I have a large data set (hourly electricity load data for 1 year, so 8760 observations). This is an excel file, so I used the readtable function to get the data. Everything works fine so far. Next, I wanted to convert the table to an array using table2array. It works fine, except that all the header names are gone. Why is this happening?
Here's my code:
inPutsT = readtable(inFile,'Sheet','load','Range','A1:D8785','ReadVariableNames',true);
inPutsA = table2array(inPutsT);
Is there a way to do this and keep the headers? Thanks
  2 件のコメント
David Fletcher
David Fletcher 2018 年 3 月 11 日
編集済み: David Fletcher 2018 年 3 月 11 日
Matrices don't have labelled columns, but you can extract the column names from the table properties and store them in a separate cell array
Chet Sharma
Chet Sharma 2018 年 3 月 11 日
Thanks David - thanks for explaining. I ended up doing what you suggested.

サインインしてコメントする。

回答 (1 件)

Peter Perkins
Peter Perkins 2018 年 3 月 15 日
Depending on what you are doing after you read in the spreadsheet, you may not need to convert to one numeric array. You might, but you can do a lot with the data in a table, and as you have discovered, tables have variable names and double matrices do not.

カテゴリ

Help Center および File ExchangeData Type Conversion についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by