Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 2.43 KB | None | 0 0
  1. %matrix1 = readInfo('kid.bmp');
  2. matrix2 = readInfo('homer.bmp');
  3. %matrix3 = readInfo('homerBin.bmp');
  4. %matrix4 = readInfo('guitarSolo.wav');
  5. %matrix5 = readInfo('english.txt');
  6. %huffman(matrix5);
  7. %p(p==0) = [];
  8. %makehistogramTXT(matrix5);
  9. % minLimit(matrix1);
  10.  %minLimit(matrix2);
  11. % minLimit(matrix3);
  12. % minLimit(matrix4);
  13. %minLimit(matrix5);
  14. %vector = matrix1(:);
  15. %groupArray(vector);
  16. makehistogram(matrix2);
  17. function a = readInfo(file)
  18.     [~,~,ext] = fileparts(file);
  19.     if(ext == '.bmp')
  20.         a = imread(file);
  21.     elseif(ext == '.wav')
  22.         [a,~] = audioread(file);
  23.     elseif(ext == '.txt')
  24.         ID = fopen(file,'r');
  25.         c =  fscanf(ID,'%s ');
  26.         c = erase(c,',');
  27.         c = erase(c,'.');
  28.         a = [];
  29.         for k = 1:length(c)
  30.             a = [a,c(k)];
  31.         end
  32.          a = uint16(a);
  33.     end
  34. end
  35. function makehistogramTXT(a)
  36.           alf = cellstr((horzcat('A':'Z','a':'z'))');
  37.           conv = cellfun(@uint16, alf);
  38.           graf = categorical(a,conv,alf);
  39.           histogram(graf);
  40.           xlim(alf);
  41. end
  42. function makehistogram (a)
  43.     xlim auto;
  44.     ylim auto;
  45.     histogram(a);
  46. end
  47.  
  48.  
  49. function x = minLimit (a)
  50.     N = histcounts(a);
  51.     N(N==0) = [];
  52.     x = -sum((N./sum(N)).*log2((N./sum(N))));
  53.     disp(x);
  54. end
  55.  
  56.  
  57. function huffman(a)
  58.     %b={sort(unique(a)) countmember(sort(unique(a)),a)};
  59.     %[x,y] = histcounts(a);    
  60.     b={sort(unique(a)) countmember(sort(unique(a)),a)};
  61.     %disp(b{1});
  62.     %disp(b{2});
  63.     %prob = b{2}/sum(b{2});
  64.     n = hufflen(b{2});
  65.     %disp(prob);
  66.     %[x,y]= huffmandict(b{1},n);
  67.     disp(n);
  68. end
  69.  
  70. function COUNT = countmember(A,B)
  71.     narginchk(2,2) ;
  72.     if ~isequal(class(A), class(B))
  73.         error('Both inputs should be of the same class.') ;
  74.     end
  75.  
  76.     if isempty(A) || isempty(B)
  77.         COUNT = zeros(size(A)) ;
  78.     else    
  79.         [AUnique, ~, j] = unique(A(:)) ; %Aunique = A sem repetiƧoes e ordenado, j = indices do A em AUnique
  80.         [~, Loc] = ismember(B, AUnique) ; %Loc = indices de AUnique em B
  81.         N = histc(Loc(:), 1:length(AUnique)) ; % conta o numero de vezes que os indices comuns aparecem
  82.         COUNT = reshape(N(j),size(A)) ;
  83.         disp(A);
  84.         disp(COUNT)
  85.     end
  86. end
  87. function countNext(matrix, a, b)
  88. vector = matrix(:);
  89. count = 0;
  90. for i=1:length(vector)
  91.     if (vector(i) == a)
  92.         if (vector(i+1) == b)
  93.             count = count+1;
  94.         end
  95.     end
  96. end
  97. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement