使用fscanf函数完成。
例如 .dat文件如下 第一行为文本的信息
1651 1 10004 1 7fe0
0x0000
0xC8F4
......
读取的方法: fid = fopen('mydata.dat');%文本在当前工作目录
result = fscanf(fid,'%x');
完成后result即数据,但是数据开头是文本第一行的信息 可以使用a = result(5:length(result)-5)去掉
关于fscanf
format
String enclosed in single quotation marks that describes each type of element (field). Includes one or more of the following specifiers.
Field Type Specifier Details
Integer, signed
%d
Base 10
%i
Base determined from the values. Defaults to base 10. If initial digits are 0x or 0X, it is base 16. If initial digit is 0, it is base 8.
%ld or %li
64-bit values, base 10, 8, or 16
Integer, unsigned
%u
Base 10
%o
Base 8 (octal)
%x
Base 16 (hexadecimal)
%lu, %lo, %lx
64-bit values, base 10, 8, or 16
Floating-point number
%f
Floating-point fields can contain any of the following (not case sensitive): Inf, -Inf, NaN, or -NaN.
%e
%g
Character string
%s
Read series of characters, until find white space.
%c
Read any single character, including white space.
(To read multiple characters, specify field length.)
%[...]
Read only characters in the brackets, until the first nonmatching character or white space.
Optionally:
To skip fields, insert an asterisk (*) after the percent sign (%). For example, to skip integers, specify %*d.
To specify the maximum width of a field, insert a number. For example, %10c reads exactly 10 characters at a time, including white space.
To skip a specific set of characters, insert the literal characters in the format. For example, to read only the floating-point number from 'pi=3.14159', specify a format of 'pi=%f'.
参考文档:http://www.mathworks.cn/cn/help/matlab/ref/sscanf.html