How to convert data set into .dat
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
i need to convert this data set into .dat http://archive.ics.uci.edu/ml/machine-learning-databases/dermatology/dermatology.data
0 Kommentare
Akzeptierte Antwort
Walter Roberson
am 8 Mai 2013
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.)
2 Kommentare
Walter Roberson
am 8 Mai 2013
Ah, I did not notice that there are some '?' in the data.
fid = fopen('dermatology.data', 'rt');
fmt = repmat('%f', 1, 35);
datacell = textscan(fid, fmt, 'delimiter', ',', 'CollectOutput', 1, 'TreatAsEmpty', '?');
fclose(fid);
data_array = datacell{1};
fid = fopen('dermadat.dat', 'w');
fwrite(fid, data_array.', 'single'); %it has NaN. Write it as single or double
fclose(fid);
In order to preserve the '?' as unknown values, the data has to be read in as single or double and has to be stored as single or double. If you want the '?' to be converted to some other value, that could also be done.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Standard File Formats finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!