How to read a txt file containing letters and number

13 ビュー (過去 30 日間)
Kenneth
Kenneth 2013 年 11 月 19 日
回答済み: Simon 2013 年 11 月 19 日
I'm trying to read a txt file for class, but I have no idea how to eliminate the text in the file, so I can reach the data. The file contain a header and some lists with dates and data in sepperate colums.

回答 (1 件)

Simon
Simon 2013 年 11 月 19 日
Hi!
You can read in with textscan as strings and convert afterwards:
% read file
fid = fopen('plante1_no_head.txt');
FC = textscan(fid, '%s%s%s%s');
fclose(fid);
% first column is date as string
% second column is time as string
% third column as double
A = FC{3};
% replace ',' with '.'
A = regexprep(A, ',', '.');
% convert to numeric
A = str2num(char(A));
% fourth column as double
B = FC{4};
% replace ',' with '.'
B = regexprep(B, ',', '.');
% convert to numeric
B = str2num(char(B));

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by