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!