0
votes

This is suppose of be very simple but I just can't get it right, probably because I don't understand something very basic.

I'm trying to figure out how to read a binary file into matlab which consists of 7 variables, each variable is written in 2 bytes (Hi and low). the first byte is MSB and others LSB. The thing is that I'm aware of fread function, but I never seem to know how to use it right when a multiple varibales are involved (just a vector of numbers of the same type are easy) so if some of you could just explain in a word or two I would be greatful.

Thank you,

1

1 Answers

2
votes

I guess you have to call fread twice, specifying time by time which format you are using (either big-endian or little-endian).

 first = fread(fileID, 1, 'int16', 0 , 'b'); %big endian
 last =  fread(fileID, 7, 'int16', 0 , 'l'); %little endian

You have also to be specific with respect to the value type of the variable stored. You say that you have 2 bytes variables, they can be 'int16', for instance. Consider the reference of fread for the possible value types with 2 bytes.