Can MATLAB read .txt like FORTRAN?
2 ビュー (過去 30 日間)
古いコメントを表示
If you have used FORTRAN, you will know that FORTRAN's formatted reading allows you to directly specify the number of characters to be read and their positions. These characters include spaces. If a variable in the specified position encounters a space, FORTRAN will automatically assign zero. However, in MATLAB, if formatted reading encounters a space, it will simply skip it. Is there any method to make MATLAB read in a way similar to FORTRAN?
0 件のコメント
採用された回答
Star Strider
2024 年 1 月 23 日
Yes.
Use the fixedWidthImportOptions function to define the field widths, then use that in conjunction with readtable to read the file.
It can be a bit of a challenge (and requires some experimentation) when initially encountered, however it definitely works.
3 件のコメント
Stephen23
2024 年 1 月 23 日
A much easier approach is to call DETECTIMPORTOPTIONS with its option "FileType" set to "fixedwidth".
Read this discussion to know why:
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Fortran with MATLAB についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!