from txt to dat file
67 次查看(过去 30 天)
显示 更早的评论
I have an program from an older version that uses a dat file looking like :
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1615923/image.png)
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
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1615928/image.png)
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
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1615933/image.png)
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
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
采纳的回答
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)
To read the file with a .dat extension, add: 'FileType','text' to the argument list.
.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Large Files and Big Data 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!