string equivalent of fread
18 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hi -
I can use
rawData = fread(fid,[59 59])
to read 59 bytes from a binary file, 59 times, convert to decimal, and put results into a 59 X 59 array.
I want to do the same, but read each hex byte literally into a string, i.e. 01 FF -> '01' 'FF', keeping the 59 X 59 structure (i.e. - 1st row: 1st 59 bytes in file as strings, keeping leading zeros; 2nd row: next 59 bytes in file as strings, keeping leading zeros; etc...)
The idea is that I want to combine some columns of strings into longer strings, convert to hex, then convert the hex to decimal.
. . ."AB" "01" . . . -> "AB01" -> AB01 -> 43777 (may not need all steps)
. . ."CC" "02" . . . -> "CC02" -> CC02 -> 52226
etc..
unknown number of rows, where "AB" and "CC" are in column 8, and "01" and "02" are in column 9.
Thoughts?
0 comentarios
Respuesta aceptada
Jan
el 13 de Sept. de 2012
Editada: Jan
el 13 de Sept. de 2012
You cannot use FREAD to read a byte from a file and convert it to something like '01' of 'FF'. FREAD reads binary data, but the conversion to a HEX string is a kind of high-level operation. This is a job for FSCANF.
Or read bytes and convert them afterwards:
data = fread(fid, [59,59], '*uint8');
xdata = sprintf('%.2x', data); % And a RESHAPE on demand.
0 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Characters and Strings 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!