MATLAB: How to convert data set into .dat

dat format

Best Answer

There is no standard format for ".dat" files. ".dat" files can be in whatever format is convenient, so it is important that whatever program is producing the file and whatever program is using the file negotiate a suitable format.
fid = fopen('dermatology.data', 'rt');
fmt = repmat('%d', 1, 35);
datacell = textscan(fid, fmt, 'delimiter', ',', 'CollectOutput', 1);
fclose(fid);
data_array = datacell{1};
fid = fopen('dermadat.dat', 'w');
fwrite(fid, data_array.', 'uint8'); %for example, write it one byte per entry
fclose(fid);
The above code sample writes one integer byte per entry, and writes the data as it reads "across" (so the second entry in the output file corresponds to the second entry on the first line.) Note: if you leave out the .' in the fwrite() then the data will be written "down" (so the second entry in the output file corresponds to the first entry on the second line.)
Related Question