从评论中,根据这篇文章:
dirName = 'C:\yourpath'; %# folder path
files = dir( fullfile(dirName,'table.*.txt') ); %# list all *.txt files, make sure you have only the txt's you are interested on inside selected path
files = {files.name}'; %# file names
data = cell(numel(files),1); %# store file contents
for i=1:numel(files)
fname = fullfile(dirName,files{i}); %# full path to file
values{i}=load(fname); %# load values from txt to variable
data{i} = histc(values{i},1:100); %# find occurences, for max value =25 change 100 to 25
end
thestructdata=[data{:}]; %# convert to matrix
for j2=1:size(thestructdata,1)
occ(j2,:)=histc(thestructdata(j2,:),1); %# find the number of occurence, 1 is present, on each line on all txt files
end
occ=[occ]'; %# gather results to an array
occperce=occ(1,:)./numel(files)*100 %# results in percentage, max value = 25, change to 100 if needed as the OP question
结果(对于 25 个值的最大值):
occ =
14 11 10 12 13 15 11 10 11 10 7 14 11 12 11 13 7 11 10 12 14 12 13 14 11
occperce =
Columns 1 through 20
56.0000 44.0000 40.0000 48.0000 52.0000 60.0000 44.0000 40.0000 44.0000 40.0000 28.0000 56.0000 44.0000 48.0000 44.0000 52.0000 28.0000 44.0000 40.0000 48.0000
Columns 21 through 25
56.0000 48.0000 52.0000 56.0000 44.0000
如果你愿意,你可以这样做删除所有 txt 文件:delete(dirName,'table.*.txt');