필터 지우기
필터 지우기

fread and fwrite application in reading file from disk

조회 수: 3 (최근 30일)
Siamack
Siamack 2013년 12월 6일
댓글: Siamack 2013년 12월 8일
hello everyone, can you read data from disk (say a pdf file) with a precision other than uint8 (say integer*4) and then re-write the numerical array back into a meaningful file on the disk?

채택된 답변

Walter Roberson
Walter Roberson 2013년 12월 6일
input_data = fread(input_fid, '*uint32');
fwrite(output_fid, input_data);
  댓글 수: 5
Walter Roberson
Walter Roberson 2013년 12월 7일
No information should be lost when you convert to 64 bit chunks. However, if you try to do arithmetic on 64 bit integers, and accidentally convert them to double precision in the process, then the result is only going to have 53 bits of precision instead of 64.
For example if you have
X = zeros(1024,1);
X(1:20) = fread(file, 20, '*uint64');
then the data would be read as uint64 but then converted to double to be stored in X because X is double. To fix you would use
X = zeros(1024,1,'uint64')
Siamack
Siamack 2013년 12월 8일
Hi! You are right! the information doesnt get lost, I just used the "typecast" function and casted the data back to uint8 (two bytes short than the original and had to be added to the end of the array) and then used fwrite to write it onto the hard and the pdf file was readable. I simply don't know where this can go wrong hence wont assume this might work for every file undergone the transitions. nonetheless thanks for the answer Walter
Regards, Siamack

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Whos에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by