感觉挺巧妙地,记录一下。
文本数据结构:
1 a
2 b
3 c
4 aa
...
基本思路是利用了fscanf
函数参考:fscanf 函数原型为 int fscanf(FILE * stream, const char * format, [argument…]); 其功能为根据数据格式(format),从输入流(stream)中读入数据,存储到argument中,遇到空格和换行时结束。
function vocabList = getVocabList()
file_path = '';
fid = fopen(file_path);
n = ; //文本总长度
vocabList = cell(n, 1);
for i = 1:n
fscanf(fid, '%d', 1);
vocabList{i} = fscanf(fid, '%s', 1);
end
fclose(fid);
end