How to read a text file and split up into several text files saving with name successively.?

2 ビュー (過去 30 日間)
aneps
aneps 2016 年 6 月 23 日
回答済み: TastyPastry 2016 年 6 月 24 日
I have a text file. It is my experimental data in three columns. The file contain results of 10 or more experiments. The data look like this:
#"+ABC Scan/Experiment1 with 12V...
#points Xvalues Yvalues
1 100.00 3359.33
2 100.00 5584.55
3 100.00 1215.56
.........
.........
257930 1222.22 18955.55
#"+ABC Scan/Experiment2 with 14V...
#points Xvalues Yvalues
1 100.00 3359.33
2 100.00 5584.55
3 100.00 1215.56
.........
.........
257930 1222.22 18955.55
....
Like this Experiment n with V Volts.... .. This is in a single .txt file. How can I split each experiment into separate txt files and save in the order of voltages or numbered successively?
  1 件のコメント
Karan Gill
Karan Gill 2016 年 6 月 24 日
Have you tried reading the file with textread, and then saving to a new file line-by-line till you hit a '#'? You can check for a '#' using strfind.

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

回答 (1 件)

TastyPastry
TastyPastry 2016 年 6 月 24 日
Well if you know your data has exactly the same number of points per experiment or you can obtain how many points there are per experiment, you can use textscan().
data = textscan(fileID,formatspec,N,'headerlines',2);
Where N is the number of lines you're reading in and the field 'headerlines' skips how many lines (the header) before starting to read data.

カテゴリ

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