Reading Data to Table

4 ビュー (過去 30 日間)
Harry Green
Harry Green 2018 年 10 月 11 日
コメント済み: Harry Green 2018 年 10 月 11 日
I'm trying to read a text file into MATLAB into table format. I'm using MATLAB 2017a.
When I right click the file on the current folder tab and click import data, it knows exactly what to do. It takes the header row of the text file and uses them for the names of the MATLAB table columns, identifies variable types, etc. I'd like to know the command equivalent. I'm aware that it is possible to generate a script from the GUI, but the generated script has hardcoded column numbers, and the column order is likely to change due to circumstances out of my hands. readtable does not work, as the extension of the file isn't supported for some reason (it's just a plain text file so I don't understand the extension limitations on readtable).
  2 件のコメント
madhan ravi
madhan ravi 2018 年 10 月 11 日
can you upload the text file?
Harry Green
Harry Green 2018 年 10 月 11 日
I've uploaded the first four lines (out of a couple of million) as an attachment to this comment , and also renamed it as a .txt, although as the function in question is part of a larger pipeline, working with files lots of other people are using, renaming files back and forth is not optimal.
Column 'TEST' is sometimes not included depending on input to genetics software, also other options can input extra columns before the p value column. If a 95% confidence interval is requested, it will add in 2 additional columns between OR and Stat.

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

回答 (1 件)

KSSV
KSSV 2018 年 10 月 11 日
file = 'AssocHead.txt' ;
opts = detectImportOptions(file,'NumHeaderLines',0);
T = readtable(file,opts) ;
  1 件のコメント
Harry Green
Harry Green 2018 年 10 月 11 日
The reason that readtable is not a possibility here is already addressed in the original question and reiterated in the comment.
The file is not a .txt, I renamed it to a .txt when uploading to make it easier for people to open directly from the browser. readtable does not take files of the desired extension. Why renaming the file is not desirable is addressed in the comment.

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

カテゴリ

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

製品


リリース

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by