フィルターのクリア

Read a txt file at a certain position

2 ビュー (過去 30 日間)
Ahmad Alsabbagh
Ahmad Alsabbagh 2016 年 5 月 3 日
編集済み: Ahmad Alsabbagh 2016 年 5 月 4 日
Dear All,
I am trying to write a code that will read a matrix at a certain position in a text file.
For example, the text file will contain the following
Mike Code
This code is helpful
The Values of k is
12
123
23.4
1234
184.2
I want the code to read the values of k. Thus, I want the code to search for the line "The Values of k is" and start taking the numbers from the following lines. (I don't know the line number)
Thanks

採用された回答

Walter Roberson
Walter Roberson 2016 年 5 月 4 日
filecontent = fileread('YourFile.txt');
filecontent = regexprep(filecontent, '.*The Values of k is\s*','');
data = sscanf(filecontent, '%f');
  1 件のコメント
Ahmad Alsabbagh
Ahmad Alsabbagh 2016 年 5 月 4 日
編集済み: Ahmad Alsabbagh 2016 年 5 月 4 日
Thanks

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeString Parsing についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by