How to convert csv file to .dat file?

131 views (last 30 days)
Hossam Amin
Hossam Amin on 18 Mar 2022
Commented: Voss on 19 Mar 2022
I want to read a csv file and save it as .dat file without the commas. How can I do so?

Accepted Answer

Voss
Voss on 18 Mar 2022
Edited: Voss on 18 Mar 2022
% 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().
  4 Comments

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!