結合我的教材P31
matlab文件操作:見電腦目錄Blessing of Dimensionality\Features\code\readFea.m 和 findImsFeaIdx.m
http://blog.sina.com.cn/s/blog_4cfb5a6201015i8q.html

例1:
路徑+文件名:d:\moon.txt
內容:
13,1,3.4
3,2.1,23
1,12,2
4,5.4,6
現在為了讀取moon中的數據存在一個數組里,可以用如下方法

fid=fopen('d:\moon.txt');

data=fscanf(fid,'%f,%f,%f',[3,inf]) ;%這里得用單引號

fclose(fid);

這時data中的數據如下:
13 3 1 4
1 2.1 12 5.4
3.4 23 2 6

例2:
數據在d:\test.txt
0.00    good 2
0.10    bot 3
1.02    yes 4
1.00    yes 5
1.00    yes 6
1.00    yes 3
1.00    yes 5
1.00    yes 6
1.00    yes 1
1.00    yes 3
1.00    yes 7
1.00    yes 3
1.00    yes 2

程序:
fid = fopen('d:\test.txt', 'r');
a = fscanf(fid, '%f    %*s %d ', [2 inf])    % It has two rows now.
fclose(fid);
a
解釋下:第一列和第二列之間有四個空格,format也要四空格哦!有三列即三種類型,要有三種format,%*s即為不輸出字符串型。

fid = fopen('E:\temp\test.txt', 'r');
a = fscanf(fid, '%f    %*s %*f ', 5)    % It has five rows and one column now. %*s %*f 即這兩個不輸出
fclose(fid);
a

程序結果為:
a =
         0
    0.1000
    1.0200
    1.0000
    1.0000