I don't understand what is the meaning of variable "samples":
filename = 'A2D.bin' ;
fid = fopen(filename)
data = fread(fid , 'uint8') ;
num_of_bits = 8 ;
samples = data * 2 / (2^num_of_bits - 1) - 1 ;
fclose(fid) ;
The code is essentially reading in a data file called A2D.bin where the elements are stored in an array called data. However, note that the fread call is assuming each chunk of 8 bits is unsigned and denotes one number in your array. This means that your data is originally containing numbers from [0,255]. samples simply normalizes this data so that it's in the range of [-1,1].
Break the steps down logically. Doing data / (2^num_of_bits - 1) is doing data / 255 which normalizes your data so that it has a range of [0,1]. Multiplying the result by 2, or doing data * 2 / (2^num_of_bits - 1) thus scales your data so that the range is now [0,2]. Finally when you subtract 1 at the end of the statement, doing data * 2 / (2^num_of_bits - 1) - 1; finally brings your data down by shifting down by -1, which makes your data become [-1,1].
Judging from the file name, this probably is the output of an analog to digital converter and you would like what the analog equivalent of each digital block of 8 bits was. Judging from the dynamic range of [-1,1], the data was most likely originating from some sort of audio file where each sample is transformed from a continuous (i.e. analog) representation into digital form.