Use Import's automatic table detection programatically

3 ビュー (過去 30 日間)
C Hinderink
C Hinderink 2016 年 9 月 19 日
コメント済み: Walter Roberson 2016 年 9 月 19 日
When opening a *.csv with header in the "Import" window, the data table is automatically selected. Is there a way this can be done programatically? The methods described elsewhere (importdata, textread, csvread etc) are less generic and require knowledge of either the number of headerlines or header/table contents.
  1 件のコメント
Walter Roberson
Walter Roberson 2016 年 9 月 19 日
Could you post an example of the first few lines of a couple of representative files you need to handle?

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

採用された回答

Jeremy Hughes
Jeremy Hughes 2016 年 9 月 19 日

その他の回答 (2 件)

Sean de Wolski
Sean de Wolski 2016 年 9 月 19 日
Have you tried readtable?
  2 件のコメント
C Hinderink
C Hinderink 2016 年 9 月 19 日
Yes, it returns: "... Found 2 variable names but 1 data columns. You may need to specify a different format string, delimiter, or number of header lines." So not the auto-table detect the GUI provides...

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


Star Strider
Star Strider 2016 年 9 月 19 日
I don’t know what you included with ‘etc.’ in the file import functions you’ve used. Have you tried xlsread? It might be able to read your .csv file and do everything you want.
  2 件のコメント
C Hinderink
C Hinderink 2016 年 9 月 19 日
xlsread does about the same. Alas the two downsides are that it returns one matrix and only numeric values.
Star Strider
Star Strider 2016 年 9 月 19 日
You can get three outputs from xlsread, the first being the numeric values, the second all strings (column headers, dates, string variables), and the third everything in the file as a cell array. See Request Numeric, Text, and Raw Data in the xlsread documentation for details.

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

カテゴリ

Help Center および File ExchangeSpreadsheets についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by