CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Feb 2014
    Posts
    1

    How do we create N matrices simultaneously in C++?

    Hi!

    I would like to create N matrices of dimension (n,k) simultaneously. Lets say for example that N=3. Could you please help me. I read the command a[n][k][N] but I don't understand how to use it.

    Please help me, I know that for some of you this question is silly but I' m new to this language and I have no one else to ask.

  2. #2
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,822

    Re: How do we create N matrices simultaneously in C++?

    You don't say of what type you want the matrices to be or whether n, k, n are constant known values at the time of compile or run-time parameters - which makes a big difference.

    The simplest way to create a 3 dimensional matrix is
    Code:
    const int n = 10;
    const int k = 5;
    const int N = 15;
    
    int matrix[n][k][N];
    The element of this matrix can be accessed as eg
    Code:
    matrix[1][3][2];
    I would like to create N matrices of dimension (n,k) simultaneously.
    However, do you actually mean that you want N matrices?
    Code:
    const int n = 10;
    const int k = 5;
    const int N = 15;
    
    typedef int mat[n][k];
    
    mat nkN[N];
    here nkN is a matrix of dimension N of type mat which is a matrix of dimensions n, k.

    What are you trying to do?
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  3. #3
    Join Date
    Mar 2014
    Location
    Warsaw, Poland
    Posts
    3

    Re: How do we create N matrices simultaneously in C++?

    Could you define "simultaneously" ? Moreover, "a[n][k][N]" is not a command, it's a definition.

  4. #4
    Join Date
    Jul 2013
    Posts
    576

    Re: How do we create N matrices simultaneously in C++?

    Quote Originally Posted by GeFo View Post
    Please help me
    I don't want to be mean but programming is not for everyone. Maybe you should do something else if you think about it.

    Do you really like to program? If you did then this is trivial with a little trial and error, a book or two, and the net.

    You can't just sit there expecting to be fed information with a silver spoon for heaven's sake. Grow up or quit.
    Last edited by razzle; March 8th, 2014 at 09:11 PM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured