Filter löschen
Filter löschen

Can MATLAB read .txt like FORTRAN?

2 Ansichten (letzte 30 Tage)
gerway
gerway am 23 Jan. 2024
Kommentiert: Star Strider am 23 Jan. 2024
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?

Akzeptierte Antwort

Star Strider
Star Strider am 23 Jan. 2024
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 Kommentare
Stephen23
Stephen23 am 23 Jan. 2024
A much easier approach is to call DETECTIMPORTOPTIONS with its option "FileType" set to "fixedwidth".
Read this discussion to know why:
Star Strider
Star Strider am 23 Jan. 2024
@gerway — As always, my pleasure!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Fortran with MATLAB finden Sie in Help Center und File Exchange

Produkte


Version

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by