How to convert csv file to .dat file?

59 ビュー (過去 30 日間)
Hossam Amin
Hossam Amin 2022 年 3 月 18 日
コメント済み: Voss 2023 年 3 月 25 日
I want to read a csv file and save it as .dat file without the commas. How can I do so?

採用された回答

Voss
Voss 2022 年 3 月 18 日
編集済み: Voss 2022 年 3 月 18 日
% read the csv file:
data = readmatrix('data.csv')
data = 4×3
1 2 3 4 5 6 7 8 9 10 11 12
% write the data to .dat file using
% space as the delimiter (no commas):
writematrix(data,'data.dat','Delimiter',' ');
% check that the .dat file looks right:
fid = fopen('data.dat');
dat_data = fread(fid,'*char').';
fclose(fid);
disp(dat_data); % looks good
1 2 3 4 5 6 7 8 9 10 11 12
I assumed the .csv file contains just numbers. If that's not the case, then you'd have to use functions other than readmatrix() and writematrix().
  6 件のコメント
Mateusz
Mateusz 2023 年 3 月 24 日
Hi! How should I edit your script in order to modify multiple files file_00XXX.csv to dat files?
Thank you in advance!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Import and Analysis についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by