How to read a .dat file, containing binary data?
조회 수: 64 (최근 30일)
이전 댓글 표시
The file is very large and ve to read by plotting those binary data without changing it to decimal format.
댓글 수: 0
채택된 답변
Iain
2014년 8월 8일
Ok. You need to open the file, for binary read access. Do that like this
fid = fopen('D:\myfile.dat','r');
Then, you need to read out what is in the file. You know the file format. You can only read out a number of bytes at a time. To read out one byte, and treat it like an unsigned 8 bit integer:
number = fread(fid,1,'*uint8');
To read out all the bytes as unsigned 8 bit integers:
numbers = fread(fid,inf,'*uint8');
That number(s) will print to screen in the range of 0 to 255. If you want to see the binary sequence that actually exists in RAM:
dec2bin(number)
To close the file:
fclose all;
댓글 수: 3
Iain
2014년 8월 11일
Well, for example:
fid = fopen('D:\myfile.dat','r'); % remember to change the filename to the file you actually want to read
tenthousand8bitunsignednumbers = fread(fid,10000,'*uint8');
fclose(fid);
plot(tenthousand8bitunsignednumbers)
추가 답변 (2개)
dhamini pasam
2016년 1월 7일
close all; clear all; clc;
fx0 = fopen('sortedOFET.txt','r'); x0 = fscanf(fx0,'%f%f%f'); Ioff=fx0(:,1); Ion=fx0(:,2); gm=fx0(:,3); [a b]=size(fx0);
% % P3HT+CuTPP_TNT(75) j=2; k=1; for i=1:2:13 j=i+1; BEoff(k)=Ioff(i); AEoff(k)=Ioff(j); diffoff(k)=AEoff(k)-BEoff(k); peroff(k)=(diffoff(k)/BEoff(k))*100;
BEon(k)=Ion(i);
AEon(k)=Ion(j);
diffon(k)=AEon(k)-BEon(k);
peron(k)=(diffon(k)/BEon(k))*100;
ratioBE(k)=BEon(k)./BEoff(k);
ratioAE(k)=AEon(k)./AEoff(k);
perratio(k)=((ratioAE(k)-ratioBE(k))./ratioBE(k))*100;
BEgm(k)=gm(i);
AEgm(k)=gm(j);
diffgm(k)=AEgm(k)-BEgm(k);
pergm(k)=(diffgm(k)/BEgm(k))*100;
j=j+2;
k=k+1;
end
peroff=peroff(:);
peron=peron(:);
pergm=pergm(:);
perratio=perratio(:);
diffoff=diffoff(:);
diffon=diffon(:);
diffgm=diffgm(:);
data=[peroff peron pergm perratio diffoff diffon diffgm];
sir,this is my code and when i am trying to open it ,i am not able to execute it and i am getting error as follows what should i do?.
??? Attempt to execute SCRIPT on_off_gm_ratio_sortedOFET as a function:
D:\matlab codes\on_off_gm_ratio_sortedOFET.m
7.22E-09 2.99E-06 -1.99E-08
8.08E-08 3.49E-06 -1.77E-08
3.25E-09 1.99E-06 -9.30E-09
4.71E-08 2.40E-06 -1.92E-08
2.94E-08 2.81E-06 -1.31E-08
7.21E-08 2.39E-06 -1.80E-08
3.29E-08 2.39E-06 -1.11E-08
3.29E-08 2.39E-06 -1.20E-07
7.03E-08 5.21E-06 -1.86E-08
1.14E-07 5.30E-06 -7.40E-08
7.92E-08 4.71E-06 -2.05E-08
8.39E-08 4.82E-06 -1.50E-08
참고 항목
카테고리
Help Center 및 File Exchange에서 Large Files and Big Data에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!