2015-02-09 146 views
1

我正在使用textscan导入数据。我可以成功导入格式正确的数据。我无法正确处理格式不正确的数据。以下是数据的格式。在Matlab中使用textscan处理数据格式不正确的数据

JeB2021Da 12-13 and stuff, 1, 1, 0, 1, 0, 1, 1, 1, 3, 1, 99, 0, 0, 0, 
JoB2021Ha 12-13 and stuff, 1, 1, 0, 1, 0, 1, 1, 0, 1, 1, 99, 2, 1, 0, 
JoP2021Co 12-13 and stuff, not enough samples 
MaA2021Be 12-13 and stuff, 1, 1, 0, 0, 0, 1, 1, 0, 1, 0, 99, 1, 0, 0, 
MaA2021Ma 12-13 and stuff, 1, 1, 0, 1, 0, 1, 1, 0, 1, 1, 99, 1, 0, 0, 

我该如何处理数据,即not enough samples?因为目前数据结构不一致。正在生产的数据结构是17 x 116 x 14。我想导入字符串,因为它在数据中。所以not enough samples将被导入。以下是我正在使用的代码。

fid = fopen('./file.txt','r'); 
fmt = ['%s %d %d %d %d %d %d %d %d %d %d %d %d %d %d']; 
d = textscan(fid, fmt, 'CollectOutput', 1,'Delimiter',',','headerLines', 1, 'EmptyValue', 0); 

我试图与EmptyValue标志来处理它,但它不工作。任何帮助是极大的赞赏。

回答

2

我不确定你的意思是什么我想导入字符串,因为它在数据中,或者更确切地说,你希望存储该字符串的位置。

但是关于刚读你的数据作为一个整体,你可以使用“TreatAsEmpty”的说法:通过查看导入的数据阵列仅包括在行进一步

d = textscan(fid, fmt, 'CollectOutput', 1,'Delimiter',',','headerLines', 1,'TreatAsEmpty','not enough samples'); 

然后,你可以修改输入零。