Borrar filtros
Borrar filtros

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

50 visualizaciones (últimos 30 días)
Gargi
Gargi el 8 de Ag. de 2014
Comentada: dhamini pasam el 7 de En. de 2016
The file is very large and ve to read by plotting those binary data without changing it to decimal format.

Respuesta aceptada

Iain
Iain el 8 de Ag. de 2014
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 comentarios
Iain
Iain el 11 de Ag. de 2014
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 el 12 de Ag. de 2014
Thanku Sir, its working....!!!
Thanks & Regards

Iniciar sesión para comentar.

Más respuestas (2)

Azzi Abdelmalek
Azzi Abdelmalek el 8 de Ag. de 2014
fid= fopen('your_file.dat');
data=fread(fid);
fclose(fid);
  3 comentarios
Azzi Abdelmalek
Azzi Abdelmalek el 8 de Ag. de 2014
Not working how? is there any error message? can you post your code?
Gargi
Gargi el 8 de Ag. de 2014
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);

Iniciar sesión para comentar.


dhamini pasam
dhamini pasam el 7 de En. de 2016
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

Categorías

Más información sobre Chemistry en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by