How to change the format of input .txt files?

2 Ansichten (letzte 30 Tage)
Ivan Mich
Ivan Mich am 8 Jun. 2022
Kommentiert: Ivan Mich am 10 Jun. 2022
Hello,
I have a question about a code. I have multiple .txt files with a specific format. Specifically , exh file has 1 header, and 4 columns with 1 tab space between each other (the 4th column has an alphanumeric format, and columns 1-3 are numbers).
I would like to change the given format, which is f7.3 1x f7.3 1x f3.1 1x character to the following
1x f6.3 4x f6.3 4x 3.1 1x character (x is tab (space) and f is float (real) number).
I am attaching an input file as an example...
Could you please help me?

Antworten (1)

Walter Roberson
Walter Roberson am 8 Jun. 2022
You may have to read the header separately. Then readtable. Then I suggest you use compose() passing in a string() object as the format. Then write the strings to a file, possibly strjoin and fwrite
  10 Kommentare
Walter Roberson
Walter Roberson am 10 Jun. 2022
Please show
class(d1{:,1})
class(d1{:,2})
class(d1{:,3})
class(d1{:,4})
class(string(d1{:,4}))
Also please remind us while matlab version you are using.
Ivan Mich
Ivan Mich am 10 Jun. 2022
well
ans =
'cell'
ans =
'cell'
ans =
'cell'
ans =
'cell'
ans =
'string'
I am using 2019a matlab version...

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu System Composer finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by