How to read txt file usinig txtscan?

3 ビュー (過去 30 日間)
Vishnu Dhakad
Vishnu Dhakad 2020 年 2 月 28 日
編集済み: dpb 2020 年 2 月 28 日
I have read attached file which has 16435 rows but I have read only 385 row because column 7 has number and character.
how to read full file?
I have used following code
fedm = fopen('Ahm-2019-VAAH.txt');
VK = textscan(fedm, '%4s, %f-%f-%f %f:%f, %f, %f, %f, %f, %f, %f, %s','delimiter','\t','headerlines', 1);
fclose(fedm);
Thanks
  1 件のコメント
dpb
dpb 2020 年 2 月 28 日
編集済み: dpb 2020 年 2 月 28 日
No wonder it fails...the format string doesn't come close to matching that file and the delimiter is a comma, not tab.
However, it is badly formed with embedded spaces in non-quoted strings so will be tough w/ textscan
readtable with an import object as the other respondent showed is probably the way to go. It would be agoodthing™ if TMW would add the text import options object to textscan but don't suppose they ever will.

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

回答 (1 件)

Ankit
Ankit 2020 年 2 月 28 日
編集済み: Ankit 2020 年 2 月 28 日
Here you go:
% Create import options, tailor the data types for multiple variables, and then read the data
filename = 'Ahm-2019-VAAH.txt';
opts = detectImportOptions(filename,'NumHeaderLines',1); % Create import options based on file content
opts.VariableNamesLine = 1;
% now pass these opts to the readtable function
T = readtable(filename, opts,'ReadVariableNames',true);
Refer below links for more details:

カテゴリ

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

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by