how to convert to binart file

조회 수: 2 (최근 30일)
sandy
sandy 2014년 4월 8일
댓글: Walter Roberson 2014년 4월 9일
given below is the values which i need to process.for that i need to save this as binary format. also i need to save as .tim format only..or any suggestions ..plz
7.543390 7.440341 35.278316 22.194822 978.857422 3.522650
7.543390 7.488090 35.278316 22.210081 978.857422 3.523718
7.527206 7.488090 35.293575 22.194822 978.857422 3.521430
7.527206 7.488090 35.293575 22.210081 978.857422 3.522803
7.527206 7.488090 35.293575 22.194822 978.857422 3.524024
7.527206 7.488090 35.293575 22.194822 978.875732 3.520972
7.527206 7.488090 35.293575 22.194822 978.857422 3.522955
7.527206 7.509514 35.293575 22.194822 978.875732 3.523566
7.532593 7.509514 35.293575 22.194822 978.875732 3.521430
7.532593 7.509514 35.293575 22.179564 978.875732 3.523261
7.532593 7.509514 35.293575 22.194822 978.875732 3.523871
output will be like this..
>Wi@hFy@éoBVåAÇpD–v@ @•z@@•z@@•z@@•z@@•z@@•z@

답변 (1개)

Walter Roberson
Walter Roberson 2014년 4월 8일
fid = fopen('YourFileNameHere', 'w');
fwrite(fid, YourMatrix, 'float32');
fclose(fid);
Note: you might need to pass transpose(YourMatrix)
I did not research .tim format; the file output format might be more complex than this.
dec2bin is not appropriate for this task.
  댓글 수: 2
sandy
sandy 2014년 4월 9일
편집: sandy 2014년 4월 9일
thanks..but if i use float32..it showing error....below is my code...
path_02='C:\Users\Desktop\sample';
path_01='C:\Users\Desktop\sample\output';
a = dir(fullfile(path_02, '*.tim'));
for i = 1:numel(a)
filename_in = fullfile(path_02, a(i).name);
fid = fopen(filename_in,'r');
ascii = fread(fid, [42,21000], 'float32');
data_values=ascii';
out = fopen(fullfile(path_01, a(i).name),'w');
fwrite(out, data_values,'float32');
fclose(out);
fclose(fid);
end
this is error im getting...
Error using fwrite
Invalid file identifier. Use fopen to generate a valid file identifier.
Error in my_sample (line 14)
fwrite(out, data_values);
Walter Roberson
Walter Roberson 2014년 4월 9일
your fopen() is failing when you want to fwrite(). You should be checking the output file identifier ("out" in your code), and you should consider printing out the reason code
[out, msg] = foen(fullfile(path_01, a(i).name),'w');
if out < 0
fprintf(2, 'Open to write failed because: %s\n', msg);
else
....
end

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

카테고리

Help CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by