how to read and create column vectors from this txt file (attached)?
1 回表示 (過去 30 日間)
古いコメントを表示
3 件のコメント
Rik
2020 年 3 月 18 日
Matlab by default treats the comma as a separator, not as part of a number. Since your columns seem to be alligned with fixed-width fields, it might make sense to parse the lines yourself by first reading the lines as char arrays, skipping the first 3 lines, replacing the commas by periods, and then using textscan on that. It might be easiest to read the date separately from the numeric values.
採用された回答
dpb
2020 年 3 月 19 日
A fixedWidthImportOptions object can help here altho the heading row doesn't quite line up to make it as trivial as could otherwise be...
opt=fixedWidthImportOptions('NumVariables',10); % create base import object w 10 variables
opt.VariableWidths=[8 10*ones(1,9)]; % set field width to match file
opt.DataLines=[4 inf]; % data starts row 4
tout=readtable('output_nostri.txt',opt); % import data; will be cellstr arrays
for i=2:10 % convert the numeric data
tout.(tout.Properties.VariableNames{i})=str2double(strrep(tout{:,i},',','.'));
end
tout.Var1=datetime(tout.Var1,'InputFormat','MMM-yyyy'); % and the time
I presume local settings will handle the month name abbreviations; the above fails on all that aren't english translations here; I would presume that comes from a locale setting for other places but I've never had the opportunity to test to know if that is so or not.
Also leaves variable names Var1 thru Var10; the column headings in line two don't exactly align with the data columns so to read it would have to do a second read of that line...
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
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!