Read .txt file with header

6 ビュー (過去 30 日間)
mdg
mdg 2012 年 4 月 25 日
コメント済み: Rena Berman 2018 年 1 月 29 日
Hello
I have a problem to read a text file into matlab with a header. The text file looks like this : http://web.gvdnet.dk/GVD002139/151.txt
i tried with this - and it works 99%
fid = fopen('151.txt','rt')
datacell = textscan(fid, '%s%s%f%f%f%f%f%f%s%s', 'HeaderLines',9);
fclose(fid);
A1 = mean(datacell{6})
The problems is that the result comes in a single column, but i want the mean of column 4,5,6 and 7 to be on a single row, so i can copy it into another textfile.
Hope anyone can help me. Thanks!
  2 件のコメント
John D'Errico
John D'Errico 2018 年 1 月 28 日
When you delete your question, you insult those who spent the time to read your question and give a thoughtful answer to it. You decrease the odds that this person will bother to answer your next question. You harm the Answers site itself, because you leave a set of answers with no question, so nobody else an ever learn from your problem.
Rena Berman
Rena Berman 2018 年 1 月 29 日
(Answers Dev) Restored edit

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

採用された回答

Oleg Komarov
Oleg Komarov 2012 年 4 月 25 日
str = urlread('http://web.gvdnet.dk/GVD002139/151.txt');
data = textscan(str, '%s%s%f%f%f%f%f%f%s%s', 'HeaderLines',9,'CollectOutput',1);
mean(data{2})

その他の回答 (2 件)

Matt Kindig
Matt Kindig 2012 年 4 月 25 日
The 'textscan' function should do the trick.
doc textscan

Walter Roberson
Walter Roberson 2012 年 4 月 25 日
A1 = mean([datacell{4:7}]);
You could also consider using the CollectOutputs option of textscan()

カテゴリ

Help Center および File ExchangeLanguage Support についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by