MATLAB: Convert csv file and write to another .m file

convert csv file and write to another .m file

Hello,
I am having problem reading in this file to matlab.
Data = readtable('100Cr6.csv','NumHeaderlines',0,'DecimalSeparator',',');
FID = fopen('kf100CR6.m', 'w');
fwrite(FID, Data, 'char');
fclose(FID);
i use the following code but it does not run successfully?
every time showing an error message:
"Error using fwrite
Cannot write value: unsupported class table
Error in convertCSV (line 15)
fwrite(FID, Data, 'char');"
i want every data in double notation (like 1231.2354) format in a .m file. so that i can use these as columns or rows of matrix.
Does anyone have a solution to this?
Many thanks.

Best Answer

filename = '100Cr6.csv';
S = fileread(filename);
S = regexprep(S, {',', ';'}, {'.', ','});
mdata = cell2mat( textscan(S, '', 'HeaderLines', 1) );