필터 지우기
필터 지우기

How to convert data set into .dat

조회 수: 3 (최근 30일)
dominix
dominix 2013년 5월 8일

채택된 답변

Walter Roberson
Walter Roberson 2013년 5월 8일
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
dominix
dominix 2013년 5월 8일
but, why does not all data completed (only 34 row).
Walter Roberson
Walter Roberson 2013년 5월 8일
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.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Standard File Formats에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by