Borrar filtros
Borrar filtros

How to convert data set into .dat

3 visualizaciones (últimos 30 días)
dominix
dominix el 8 de Mayo de 2013

Respuesta aceptada

Walter Roberson
Walter Roberson el 8 de Mayo de 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 comentarios
dominix
dominix el 8 de Mayo de 2013
but, why does not all data completed (only 34 row).
Walter Roberson
Walter Roberson el 8 de Mayo de 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.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Standard File Formats en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by