read .txt file data with data between specific lines "string" .
現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
古いコメントを表示
I want to read data between ( strings ) line starting from " *Node " and
ending at and next (strings ) line " *Element, type=C3D4" .
採用された回答
The textscan function using a numeric format descriptor string will automatically stop when it encounters:
*Element, type=C3D4
so this is actually a straightforward problem:
fidi = fopen('Copy_of_Job-1.txt','rt');
D = textscan(fidi, '%f%f%f%f', 'HeaderLines',9, 'Delimiter',',', 'CollectOutput',1);
fclose(fidi);
with ‘D’ being a (1418x4) double matrix.
7 件のコメント
With only two sections, and changing lines of text and changing format, your file needs specific and different textscan calls for the two sections:
fidi = fopen('Copy_of_Job-1.txt','rt');
D{1} = textscan(fidi, '%f%f%f%f', 'HeaderLines',9, 'Delimiter',',', 'CollectOutput',1);
txtline = fgets(fidi);
D{2} = textscan(fidi, '%f%f%f%f%f', 'Delimiter',',', 'CollectOutput',1);
fclose(fidi);
D1 = cell2mat(D{1}); % First Section
D2 = cell2mat(D{2}); % First Section
with ‘D1’ being a (1418 x 4) double, and ‘D2’ being a (6584 x 5) double.
Different files with different requirements would of course require different code.
jahanzaib ahmad
2019 年 6 月 27 日
編集済み: jahanzaib ahmad
2019 年 6 月 27 日
thankyou got it .but i want code to find the next string itself and read the data upto next string .
how can i find the line number with the matching strings ? e.g *nodes and **Element, type=C3D4
jahanzaib ahmad
2019 年 6 月 27 日
編集済み: jahanzaib ahmad
2019 年 6 月 27 日
the file format in my case remains constant with same strings .its abaqus .inp file . i want to read the data between strings and modify it .i changed it to .txt .
I am not certain what you are asking. I believe the code I posted in my Comment will do what you want.
If your file format remains the same, my code will work with all your files.
thankyou . i got it .. . ur code works perfectly
As always, my pleasure.
I appreciate your compliment.
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Data Import and Analysis についてさらに検索
タグ
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の MathWorks のサイトは、お客様の地域からのアクセスが最適化されていません。
南北アメリカ
- América Latina (Español)
- Canada (English)
- United States (English)
ヨーロッパ
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
