How can I open a .txt file in a directory, regardless of its name??
2 ビュー (過去 30 日間)
古いコメントを表示
Hi,
I am coupling MATLAB with ANSYS for structural optimization and I need to open an output file generated by ANSYS. The problem is that ANSYS gives the last output, but the output filename is different in each iteration, as it in the format xxx.txt, where xxx is the last substep. The problem is that the number of substeps can vary from 100 to 400. I must read the output file with a MATLAB code, however, I can only define the output as a specific file (such as 100.txt or 200.txt). How can I tell MATLAB to open the only .txt file in a given directory, regardless of its name? I am defining a function, and I call the file 100.txt. How can I change it to read whatever file with .txt extension is in that directory? A sample of the code is:
Problem.ansys.output_file = 'C:\Users\Johnny\Desktop\blow_moulding_2\blow_moulding_viscoelastic\520_files\dp0\PFL-BM\PFL\Outputs\xml\100.txt';
Best regards,
0 件のコメント
採用された回答
Stephen23
2017 年 11 月 30 日
編集済み: Stephen23
2017 年 11 月 30 日
Use dir to get the filename:
P = 'C:\Users\Johnny\Desktop\blow_moulding_2\blow_moulding_viscoelastic\520_files\dp0\PFL-BM\PFL\Outputs\xml';
S = dir(fullfile(P,'*.txt'));
Z = fullfile(P,S.name)
You should of course check how many files it identifies, and handle the cases 0 and >1.
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Startup and Shutdown についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!