I use this code fragment to read a binary file into a array
fid=fopen('data.bin','rb') % opens the file for reading A = fread(fid, count, 'int16') % reads _count_ elements and stores them in A
But it reads the file into a 1 dimensional array. Is there a direct method to read a binary file into a 2d array without me having to write loops to do that ?
preguntado el 08 de noviembre de 11 a las 16:11
Creo que esto es lo que necesitas:
fid = fopen('data.bin','rb'); A = fread(fid, [rows columns], 'int16')
You must know beforehand the number of rows/columns of the matrix you want to read. This way you read the values as an array, then reshape the result into the expected size:
A = reshape(A,[r c]);