Dynamic array of matrices

Discussion in 'C Programming' started by Prototipo, Nov 1, 2003.

  1. Prototipo

    Prototipo Guest

    Hi! I need to dynamically create X vectors of matrices (with a known
    size of 5x5). It's like a three-dimensional matrix with 2 known
    dimensions and the third unknown.

    I have something like:

    int *matrix[5][5];

    But I don't know how to allocate memory for X matrices. How can I do
    it?

    thanks
     
    Prototipo, Nov 1, 2003
    #1
    1. Advertising

  2. Prototipo

    Tom St Denis Guest

    "Prototipo" <> wrote in message
    news:...
    > Hi! I need to dynamically create X vectors of matrices (with a known
    > size of 5x5). It's like a three-dimensional matrix with 2 known
    > dimensions and the third unknown.
    >
    > I have something like:
    >
    > int *matrix[5][5];
    >
    > But I don't know how to allocate memory for X matrices. How can I do
    > it?


    The same way you do with all other matrices

    matrix = calloc(X, sizeof(matrix[0]));

    Tom
     
    Tom St Denis, Nov 1, 2003
    #2
    1. Advertising

  3. Prototipo

    Artie Gold Guest

    Prototipo wrote:
    > Hi! I need to dynamically create X vectors of matrices (with a known
    > size of 5x5). It's like a three-dimensional matrix with 2 known
    > dimensions and the third unknown.
    >
    > I have something like:
    >
    > int *matrix[5][5];
    >
    > But I don't know how to allocate memory for X matrices. How can I do
    > it?
    >


    See:

    http://www.eskimo.com/~scs/C-faq/q6.16.html

    [You *did* read the various FAQs *first*, didn't you? ;-)]

    HTH,
    --ag
    --
    Artie Gold -- Austin, Texas
    Oh, for the good old days of regular old SPAM.
     
    Artie Gold, Nov 1, 2003
    #3
  4. Prototipo

    dis Guest

    "Prototipo" <> wrote in message
    news:...

    > Hi! I need to dynamically create X vectors of matrices (with a known
    > size of 5x5). It's like a three-dimensional matrix with 2 known
    > dimensions and the third unknown.
    >
    > I have something like:
    >
    > int *matrix[5][5];
    >
    > But I don't know how to allocate memory for X matrices. How can I do
    > it?



    #include <stdlib.h>
    int main(void)
    {
    int X = 5;
    int (*matrix)[5][5] = malloc(X * sizeof *matrix);
    if (matrix != NULL)
    {
    /* allocation succeeded */
    }
    free(matrix);
    return 0;
    }
     
    dis, Nov 1, 2003
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. mkokelma

    split matrices

    mkokelma, Oct 21, 2004, in forum: VHDL
    Replies:
    5
    Views:
    782
    mkokelma
    Oct 22, 2004
  2. tommy

    matrices

    tommy, Dec 3, 2004, in forum: C++
    Replies:
    3
    Views:
    604
    Victor Bazarov
    Dec 3, 2004
  3. Nils Wagner
    Replies:
    1
    Views:
    492
    David M. Cooke
    Oct 22, 2004
  4. George Sakkis

    Sparse matrices

    George Sakkis, Sep 27, 2005, in forum: Python
    Replies:
    0
    Views:
    433
    George Sakkis
    Sep 27, 2005
  5. ssylee
    Replies:
    2
    Views:
    440
    ssylee
    Jan 14, 2009
Loading...

Share This Page