試試這個代碼來讀取數據:
filename = 'yourfilename.txt';
fid = fopen(filename,'r');
% If you have a line with column headers use those 3 lines. Comment if not.
colnames = fgetl(fid);
colnames = textscan(colnames, '%s','delimiter','\t');
colnames = colnames{:};
% Reading the data
tsformat = [repmat('%f ',1,7129) '%s'];
datafromfile = textscan(fid,tsformat,'delimiter','\t','CollectOutput',1);
fclose(fid);
% Get the data from the cell array
data = datafromfile{1};
labels = datafromfile{2};
編輯 要分開您的數據集訓練和測試,做一些像這樣的:
train_samp = 1:19;
test_samp = 20:38;
train_data = data(train_samp,:);
test_data = data(test_samp,:);
train_label = labels(train_samp);
test_label = labels(test_samp);
您也可以單獨樣本隨機:
samp_num = size(data,1);
test_num = 19;
randorder = randperm(samp_num);
train_samp = randorder(test_num+1:samp_num);
test_samp = randorder(1:test_num);
我沒有做換位data = data';
。 如果您需要,只需切換行和列的索引在上面的代碼:
train_data = data(:,train_samp);
test_data = data(:,test_samp);
來源
2010-05-08 00:25:10
yuk
您的文件格式,更重要的是你怎麼看這些數據?顯示你的代碼和一些數據樣本。 – yuk 2010-05-08 00:11:40