read a formated text
2 ビュー (過去 30 日間)
古いコメントを表示
How can I read the Information from the following text file?
<content d="2000-11-02" o="21.410" h="21.800" c="21.600" l="21.310" v="21014" bl="" />
<content d="2000-11-03" o="21.610" h="21.680" c="21.420" l="21.380" v="7412" bl="" />
<content d="2000-11-06" o="21.420" h="21.450" c="21.370" l="21.330" v="8795" bl="" />
<content d="2000-11-07" o="21.380" h="21.500" c="21.360" l="21.280" v="9994" bl="" />
What interests me are
"2000-11-06", 21.420, 21.450, 21.370, 21.330, 8795
I tried
textscan(fid, '\t<content d="%4d-%2d-%2d" o="%f" h="%f" c="%f" l="%f" v="%f" bl="" />')
or
textscan(fid, '\t<content d="%q" o="%f" h="%f" c="%f" l="%f" v="%f" bl="" />')
But it doesn't work. Anyone can help?
BTW, converting dates using
dates = cellfun(@(x)datenum(x, 'yyyy-mm-dd'), dates);
is kind of slow. Anyone knows a faster way?
0 件のコメント
採用された回答
dpb
2014 年 12 月 12 日
Forget the '\t' in the first format string; textscan uses it as one of the default delimiters, anyway.
I pasted one line in to command window --
textscan(s, '<content d="%4d-%2d-%2d" o="%f" h="%f" c="%f" l="%f" v="%f" bl="" />')
ans =
[2000] [11] [2] [21.4100] [21.8000] [21.6000] [21.3100] [21014]
>>
その他の回答 (2 件)
Thorsten
2014 年 12 月 15 日
i1 = findstr(S, '<content');
i2 = findstr(S, '/>');
i2 = i2(find(i2>i1(1), 1, 'first'):end) + 1;
for i=1:numel(i1)
R(i,:) = textscan(S(i1(i):i2(i)), '<content d="%4d-%2d-%2d" o="%f" h="%f" c="%f" l="%f" v="%f" bl="" />')
end
参考
カテゴリ
Help Center および File Exchange で Data Import and Export についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!