from txt to dat file

조회 수: 73 (최근 30일)
Ellen
Ellen 2024년 2월 13일
댓글: Dyuman Joshi 2024년 2월 17일
I have an program from an older version that uses a dat file looking like :
when I open it using import data.
I want to use data from another station and downloaded the data (attached) (there are no fieldnames)
I wat tot import the data using import data to convert it tot the same output as the original file.
the text file gives the data as:
1996.0417; 6701; 0;000
1996.1250; 6773; 0;000
1996.2083; 6684; 0;000
1996.2917; 6760; 0;000
1996.3750; 6849; 0;000
1996.4583; 6861; 0;000
I know how to split the third column and change both new one tot number but when i change de delimiter to space this happens
I dont know how to proceed from here. And I cannot find a tutorial how to proceed. Can someont tell me which settings i need (table array etc) and how to save the file as a *.dat file
Kind regards, Ellen
  댓글 수: 4
VBBV
VBBV 2024년 2월 13일
Yes. Matlab can read those file extensions. In your case it's recommended to save it as .txt file which you can later renamed it as .dat file
Dyuman Joshi
Dyuman Joshi 2024년 2월 17일
Note by @Ellen - "that seems to be the solution for me thx".

댓글을 달려면 로그인하십시오.

채택된 답변

Star Strider
Star Strider 2024년 2월 13일
I would use either readtable or readmatrix, specifying the semicolon as the delimiter and ignoring the space delimiter —
% r = fileread('psmsl_monthly_22.txt') % Original File Content & Format
format long
T1 = readtable('psmsl_monthly_22.txt', 'Delimiter',{';'}, 'HeaderLines',1)
T1 = 324×4 table
Var1 Var2 Var3 Var4 _________ ____ ____ ____ 1996.0417 6701 0 0 1996.125 6773 0 0 1996.2083 6684 0 0 1996.2917 6760 0 0 1996.375 6849 0 0 1996.4583 6861 0 0 1996.5417 6888 0 0 1996.625 6905 0 0 1996.7083 6873 0 0 1996.7917 6948 0 0 1996.875 7114 0 0 1996.9583 6855 0 0 1997.0417 6785 0 0 1997.125 6974 0 0 1997.2083 6876 0 0 1997.2917 6829 0 0
To read the file with a .dat extension, add: 'FileType','text' to the argument list.
.

추가 답변 (1개)

VBBV
VBBV 2024년 2월 13일
편집: VBBV 2024년 2월 13일
Select the desired range in Range field box. i.e. Only the categorical column. It seems you have selected a array of columns in range
  댓글 수: 1
VBBV
VBBV 2024년 2월 13일
Range: C1:C324
Then apply the space delimiter

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

제품


릴리스

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by