** textread函數(shù)**
語法:
method one
[A,B,C,...] = textread(filename,format);
method two
[A,B,C,...] = textread(filename,format,N)
method three
[...] = textread(...,param,value,...)
介紹:使用指定格式format
,從filename
中讀入數(shù)據(jù)放入A,B,C...
,假設(shè)一個(gè)txt文件t.txt如下:
5.1 3.5 1.4 0.2 1
4.9 3 1.4 0.2 1
4.7 3.2 1.3 0.2 1
4.6 3.1 1.5 0.2 1
5 3.6 1.4 0.2 1
5.4 3.9 1.7 0.4 1
4.6 3.4 1.4 0.3 1
5 3.4 1.5 0.2 1
4.4 2.9 1.4 0.2 1
4.9 3.1 1.5 0.1 1
5.4 3.7 1.5 0.2 1
4.8 3.4 1.6 0.2 1
4.8 3 1.4 0.1 1
4.3 3 1.1 0.1 1
若要讀取其中的每列椭豫,并將每列放入f1,f2,f3,f4,c
中,可以通過下面的方式進(jìn)行讀取倡鲸。
[f1,f2,f3,f4,c] = textread('t.txt','%f%f%f%f%f');
%f%f%f%f%f'
控制讀入數(shù)據(jù)的格式特漩。其他格式可以參見下表。
對(duì)于method two嘹黔,同理如上账嚎,只不過可以通過
N
限制讀入數(shù)據(jù)的數(shù)目。對(duì)于method three儡蔓,這個(gè)方法是最靈活的郭蕉,可以通過參數(shù)對(duì)
param-value
自定義讀入數(shù)據(jù)和讀入方式。參見下表喂江。具體操作參見matlab doc召锈。