Advertisement
mate2code

cv2cm and cm2cv for class bin

Mar 30th, 2013
725
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 0.90 KB | None | 0 0
  1. % functions to get a Walsh permutation's compression matrix from the compression vector and vice versa
  2. % for the bin class see http://pastebin.com/K02wGsae
  3.  
  4. function y = cv2cm(x)
  5. % compression vector of type bin to compression matrix of type logical
  6.     Long = length(x) ;
  7.     Mat = false(Long) ;
  8.     for n = 1 : Long
  9.         for k = 1 : x(n).Weight
  10.             Mat( x(n).Expo(k)+1 , n ) = 1 ;
  11.         end
  12.     end
  13.     y = Mat ;
  14. end
  15.  
  16. function y = cm2cv(x)
  17. % compression matrix of type logical to compression vector of type bin
  18.     Long = size(x,1) ;
  19.     CV = bin([1 Long],'pre') ;
  20.     for n=1:Long
  21.         Weight = sum(x(:,n)) ;
  22.         Expo = zeros( 1 , Weight ) ;
  23.         Count = 1 ;
  24.         for m=1:Long
  25.             if x(m,n) == 1
  26.                 Expo(Count) = m-1 ;
  27.                 Count = Count + 1 ;
  28.             end
  29.         end
  30.         CV(n) = bin(Expo) ;
  31.     end
  32.     y = CV ;
  33. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement