Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- %matrix1 = readInfo('kid.bmp');
- matrix2 = readInfo('homer.bmp');
- %matrix3 = readInfo('homerBin.bmp');
- %matrix4 = readInfo('guitarSolo.wav');
- %matrix5 = readInfo('english.txt');
- %huffman(matrix5);
- %p(p==0) = [];
- %makehistogramTXT(matrix5);
- % minLimit(matrix1);
- %minLimit(matrix2);
- % minLimit(matrix3);
- % minLimit(matrix4);
- %minLimit(matrix5);
- %vector = matrix1(:);
- %groupArray(vector);
- makehistogram(matrix2);
- function a = readInfo(file)
- [~,~,ext] = fileparts(file);
- if(ext == '.bmp')
- a = imread(file);
- elseif(ext == '.wav')
- [a,~] = audioread(file);
- elseif(ext == '.txt')
- ID = fopen(file,'r');
- c = fscanf(ID,'%s ');
- c = erase(c,',');
- c = erase(c,'.');
- a = [];
- for k = 1:length(c)
- a = [a,c(k)];
- end
- a = uint16(a);
- end
- end
- function makehistogramTXT(a)
- alf = cellstr((horzcat('A':'Z','a':'z'))');
- conv = cellfun(@uint16, alf);
- graf = categorical(a,conv,alf);
- histogram(graf);
- xlim(alf);
- end
- function makehistogram (a)
- xlim auto;
- ylim auto;
- histogram(a);
- end
- function x = minLimit (a)
- N = histcounts(a);
- N(N==0) = [];
- x = -sum((N./sum(N)).*log2((N./sum(N))));
- disp(x);
- end
- function huffman(a)
- %b={sort(unique(a)) countmember(sort(unique(a)),a)};
- %[x,y] = histcounts(a);
- b={sort(unique(a)) countmember(sort(unique(a)),a)};
- %disp(b{1});
- %disp(b{2});
- %prob = b{2}/sum(b{2});
- n = hufflen(b{2});
- %disp(prob);
- %[x,y]= huffmandict(b{1},n);
- disp(n);
- end
- function COUNT = countmember(A,B)
- narginchk(2,2) ;
- if ~isequal(class(A), class(B))
- error('Both inputs should be of the same class.') ;
- end
- if isempty(A) || isempty(B)
- COUNT = zeros(size(A)) ;
- else
- [AUnique, ~, j] = unique(A(:)) ; %Aunique = A sem repetiƧoes e ordenado, j = indices do A em AUnique
- [~, Loc] = ismember(B, AUnique) ; %Loc = indices de AUnique em B
- N = histc(Loc(:), 1:length(AUnique)) ; % conta o numero de vezes que os indices comuns aparecem
- COUNT = reshape(N(j),size(A)) ;
- disp(A);
- disp(COUNT)
- end
- end
- function countNext(matrix, a, b)
- vector = matrix(:);
- count = 0;
- for i=1:length(vector)
- if (vector(i) == a)
- if (vector(i+1) == b)
- count = count+1;
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement