フィルターのクリア

How to read a .dat file, containing binary data?

50 ビュー (過去 30 日間)
Gargi
Gargi 2014 年 8 月 8 日
コメント済み: dhamini pasam 2016 年 1 月 7 日
The file is very large and ve to read by plotting those binary data without changing it to decimal format.

採用された回答

Iain
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
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)
Gargi
Gargi 2014 年 8 月 12 日
Thanku Sir, its working....!!!
Thanks & Regards

サインインしてコメントする。

その他の回答 (2 件)

Azzi Abdelmalek
Azzi Abdelmalek 2014 年 8 月 8 日
fid= fopen('your_file.dat');
data=fread(fid);
fclose(fid);
  3 件のコメント
Azzi Abdelmalek
Azzi Abdelmalek 2014 年 8 月 8 日
Not working how? is there any error message? can you post your code?
Gargi
Gargi 2014 年 8 月 8 日
Sir, the error msg m getting is as follows
Error using fread Out of memory. Type HELP MEMORY for your options.
Error in Untitled (line 2) data=fread(fid);

サインインしてコメントする。


dhamini pasam
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
  1 件のコメント
dhamini pasam
dhamini pasam 2016 年 1 月 7 日
sorry for posting here

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeChemistry についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by