What is the best way to organize two header lines in a Table?

49 ビュー (過去 30 日間)
Kazi Alam
Kazi Alam 2021 年 5 月 10 日
コメント済み: Walter Roberson 2021 年 5 月 11 日
Hallo, Thanks for Reading!
My dataset has two header lines. The dataset is read from a '*.xlxs' file where line 1 contains the Variable Group names and Line 2 contains Variable Names. I need both for my data classification and exploration. How can I read it with readtable function?
I have tried detectImportOptions with VariableUnitsLine and VariableDescriptionsLine. Everytime, MATLAB returned the following error.
Error:
Unrecognized property '*' for class
'matlab.io.spreadsheet.SpreadsheetImportOptions'.
If possible, could you give me an example on how to organize them ?
Example:
% Line 1: Climate Data
% Line 2: {'Temperature', 'Humidity'}
  12 件のコメント
Kazi Alam
Kazi Alam 2021 年 5 月 11 日
編集済み: Kazi Alam 2021 年 5 月 11 日
Now I have the following error.
Error using matlab.io.ImportOptions/readtable (line 653)
Comparison between double and string is not supported.
Walter Roberson
Walter Roberson 2021 年 5 月 11 日
I am not sure which version you are using; current versions specifically permit a vector of integers for the VariableNamesRange see https://www.mathworks.com/help/matlab/ref/matlab.io.spreadsheet.spreadsheetimportoptions.html#bvetiw8-1_sep_bvetiw8-1-VariableNamesRange
But you could try
opts.VariableNamesRange = '2:2';

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

回答 (1 件)

Walter Roberson
Walter Roberson 2021 年 5 月 10 日
If you must use readtable() then you are going to need two calls, one to read the first header line.
Alternately you could use readcell() and extract the first header line and construct a table from the remaining lines.

カテゴリ

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