Thread: hadamard matrix

  1. #1
    Registered User
    Join Date
    Feb 2004

    Post hadamard matrix


    What would the best method be to create a Hadamard matrix in C++?

    0: 11111111111111111111111111111111
    1: 11111111111111110000000000000000
    2: 11111111000000000000000011111111
    3: 11111111000000001111111100000000
    4: 11110000000011111111000000001111
    5: 11110000000011110000111111110000
    6: 11110000111100000000111100001111
    7: 11110000111100001111000011110000
    8: 11000011110000111100001111000011
    9: 11000011110000110011110000111100
    10: 11000011001111000011110011000011
    11: 11000011001111001100001100111100
    12: 11001100001100111100110000110011
    13: 11001100001100110011001111001100
    14: 11001100110011000011001100110011
    15: 11001100110011001100110011001100

    I'd like to store the matrix in a 2 dimensional array with dimensions 16 x 32.

    Is this correct so far..?

    int f, N, had[16][32]; 
                     for (f=0; f<16; f++); 
                           for (N=0; N<32; N++); 
                                 had[f][N] =

    So i'm now looking to fill the array with the hadamard values and I don't know how to do this. Any help would be very much appreciated.


  2. #2
    Registered User
    Join Date
    Apr 2002
    Are you having problems actually computing the hadamard matrix values? Or the coding behind it? Since you say you have a 16x32 matrix with only 2 values ( usually -1 and 1's but 0's and 1's is fine ), you can do a trick.

    Just have an array of 16 integers and let the integer bits (assuming an integer is 4 bytes on your system ) stand for the rows. So if you decalred:

    int Matrix[16];
    then you are subscripting into the rows and then you can use bitwise manipulation to check individual bits. You could wrap this nicely in a class and save on storage. If storage isn't a primary concern to you then feel free to declare the 2D array.
    "...the results are undefined, and we all know what "undefined" means: it means it works during development, it works during testing, and it blows up in your most important customers' faces." --Scott Meyers

  3. #3
    Registered User
    Join Date
    Nov 2001
    One solution is dynamic allocation.


  4. #4
    Registered User
    Join Date
    Feb 2004
    thanks for the replies. Thanks for the pointer MrWizard that's just what i was looking for.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C - access violation
    By uber in forum C Programming
    Replies: 2
    Last Post: 07-08-2009, 01:30 PM
  2. Matrix Help
    By HelpmeMark in forum C++ Programming
    Replies: 27
    Last Post: 03-06-2008, 05:57 PM
  3. Gauss-Jordan Matrix Inversion in C++
    By Max_Power82 in forum C++ Programming
    Replies: 3
    Last Post: 12-03-2006, 08:31 PM
  4. Matrix and vector operations on computers
    By DavidP in forum A Brief History of
    Replies: 11
    Last Post: 05-11-2004, 06:36 AM