Reading Data to Table
조회 수: 3 (최근 30일)
이전 댓글 표시
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
답변 (1개)
KSSV
2018년 10월 11일
file = 'AssocHead.txt' ;
opts = detectImportOptions(file,'NumHeaderLines',0);
T = readtable(file,opts) ;
참고 항목
카테고리
Help Center 및 File Exchange에서 Text Files에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!