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!