我有一个大的制表符分隔的文件(10000行,15000列),并想将其导入到Matlab。如何使用textscan读取文件?
我已经尝试使用textscan功能通过以下方式将其导入:
function [C_text, C_data] = ReadDataFile(filename, header, attributesCount, delimiter,
attributeFormats, attributeFormatCount)
AttributeTypes = SetAttributeTypeMatrix(attributeFormats, attributeFormatCount);
fid = fopen(filename);
if(header == 1)
%read column headers
C_text = textscan(fid, '%s', attributesCount, 'delimiter', delimiter);
C_data = textscan(fid, AttributeTypes{1, 1}, 'headerlines', 1);
else
C_text = '';
C_data = textscan(fid, AttributeTypes{1, 1});
end
fclose(fid);
AttributeTypes {1,1}是字符串至极描述变量类型对于每一列(在这种情况下,有14740浮子和260个字符串类型变量,因此AttributeTypes {1,1}的值为'%f%f ......%f%s%s ...%s,其中%f重复14740次,%s为260次) 。
当我尝试执行
>> [header, data] = ReadDataFile('data/orange_large_train.data.chunk1', 1, 15000, '\t', types, size);
头阵列似乎是正确的(列名已经被正确读取)。
数据是一个1 x 15000数组(仅导入第一行而不是10000)并且不知道是什么导致了这种行为。
我想这个问题是在这一行造成的:
C_data = textscan(fid, AttributeTypes{1, 1});
,但不知道什么可能是错误的,因为在帮助说明一个类似的例子。
如果你们中的任何人提出了解决问题的方法,我将非常感激 - 如何读取所有10000行。