我有一个具有以下信息格式的文本文件:
Name1 34 25 36 46
Name1 23 53 15 86
Name1 25 25 87 35
Name2 76 22 44 55
Name2 88 88 88 88
Name3 11 11 11 11
Name3 55 66 88 88
Name3 88 88 88 88
Name3 00 00 00 00
有不同的“名称”,我必须将每个名称排列到一个数组槽中。然后,我需要另一种方法来将与每一行关联的日期分配到该特定位置。例如,第一个 Name1 可能有数组 {0},但我还需要以某种方式关联 34、24、36 和 46。我还需要区分不同的名称。做这个的最好方式是什么?2x2 阵列似乎不是解决方案。
到目前为止,我所拥有的是这样的:
%# read the whole file to a temporary cell array
fid = fopen(filename,'rt');
tmp = textscan(fid,'%s','Delimiter','\n');
fclose(fid);
%# remove the lines starting with headerline
tmp = tmp{1};
idx = cellfun(@(x) strcmp(x(1:10),'headerline'), tmp);
tmp(idx) = [];
%# split and concatenate the rest
result = regexp(tmp,' ','split');
result = cat(1,result{:});
%# delete temporary array (if you want)
clear tmp
有人可以告诉我安排信息的最佳方式吗?谢谢,非常感谢您的帮助。