Matlab: read and calculate percentage of occurrence values from text files -
i have set of .txt files name: table.iterations.txt
iterations = 1:10000
(so table.01.txt
, table.02.txt
, table.1001.txt
etc, each file size lower 2kb). each txt file contains values, integers without decimals in different lines p.e.:
table.01.txt table.02.txt ... table.1001.txt 2 5 32 5 19 37 19 45 58 52 88 62 62 89 75 95 80 99 88 100
each txt file can contain different number of values, 0<value<101
.
i need on how read files find percentage of occurrence of value inside txt files. on above rough example, value 2 present 1 time, value 5 2 times, value 100 1 time etc.
thank in advance.
from comments, according this post:
dirname = 'c:\yourpath'; %# folder path files = dir( fullfile(dirname,'table.*.txt') ); %# list *.txt files, make sure have txt's interested on inside selected path files = {files.name}'; %# file names data = cell(numel(files),1); %# store file contents i=1:numel(files) fname = fullfile(dirname,files{i}); %# full path file values{i}=load(fname); %# load values txt variable data{i} = histc(values{i},1:100); %# find occurences, max value =25 change 100 25 end thestructdata=[data{:}]; %# convert matrix j2=1:size(thestructdata,1) occ(j2,:)=histc(thestructdata(j2,:),1); %# find number of occurence, 1 present, on each line on txt files end occ=[occ]'; %# gather results array occperce=occ(1,:)./numel(files)*100 %# results in percentage, max value = 25, change 100 if needed op question
results (for 25 value's max value):
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
if like, may delete txt files doing this: delete(dirname,'table.*.txt');