how to read the data byte by byte in .raw file?

34 views (last 30 days)
I have .raw file of size around 150MB and the data is stored in the form of hexadecimal , i want to read this data byte level and to display. I am giving here example of how data is stored in file.
00000 00 12 06 25 32 45 02 35 C2 00 B7 00 FD 00 4C 00
00010 63 00 B5 00 21 00 A3 00 61 00 D7 00 5A 00 25 00
00020 ---------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------
I am not able to read this file , suggest me how to read this file and display the contents .
thank you.

Answers (2)

Cris LaPierre
Cris LaPierre on 7 Mar 2021
See the documentation for fread (Read data from binary file). There are some examples on that page that should help you get started.
For an alternate approach using textscan, see this answer:
  2 Comments
chenna kesavulu ganna
chenna kesavulu ganna on 8 Mar 2021
I have already gone through this textscan and fread but not able to load this file to new variable. Here the file extension is .raw format. Is there any command or function to convert.raw to.text/.csv format
Cris LaPierre
Cris LaPierre on 8 Mar 2021
The extension doesn't really matter. What's more important is the actual formatting inside the file.

Sign in to comment.


Walter Roberson
Walter Roberson on 8 Mar 2021
if ispc()
filename = 'myfile.raw';
S = fileread(filename);
else
%get the data into MATLAB as we are not given a sample file
S = {'00000 00 12 06 25 32 45 02 35 C2 00 B7 00 FD 00 4C 00'
'00010 63 00 B5 00 21 00 A3 00 61 00 D7 00 5A 00 25 00'
'00020 31 41 59 26 59 35'}; %illustrating ending short
S = strjoin(S, '\n');
end
S = regexprep(S, '^[0-9a-fA-F]{5}', '', 'lineanchors')
S =
' 00 12 06 25 32 45 02 35 C2 00 B7 00 FD 00 4C 00 63 00 B5 00 21 00 A3 00 61 00 D7 00 5A 00 25 00 31 41 59 26 59 35'
bytes = uint8(sscanf(S, '%2x', [1 inf]))
bytes = 1×38
0 18 6 37 50 69 2 53 194 0 183 0 253 0 76 0 99 0 181 0 33 0 163 0 97 0 215 0 90 0
I changed the approach I was going to post involving textscan() in order to instead use a method that works even if the final line is not an exact multiple of 16 bytes. The textscan() approach I was going to use was fine at reading the data, but it padded the unused spaces on the line with 00, and even if I had changed that to a different constant there would have been the potential for problems. Besides, this approach works perfectly well.
  8 Comments
chenna kesavulu ganna
chenna kesavulu ganna on 19 Mar 2021
now i am able to read this hex data in decimal format in other file, but the thing here is first 4 words represents the time tag while reading in decimal format its again converting to decimal(that is already in decimal), i want to read the first words as it is.
now i want to scan my data row wise(in .rdt file format) and count the number of times the pattern is occured in the file( the pattern is like continuous words in a row are like 120 135 78) make a counter value and proceed further for same and counts the counter value for how many times pattern is repeated in .rdt file and scanning should be row wise in .rdt file.
thank you.
Walter Roberson
Walter Roberson on 19 Mar 2021
? MacroMedia RoboView files? That kind of .rdt ?

Sign in to comment.

Categories

Find more on Data Import and Export in Help Center and File Exchange

Tags

Products

Community Treasure Hunt

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

Start Hunting!