Results 1 to 4 of 4

Thread: how do you setlength of a matrix?

  1. #1
    Join Date
    Feb 2008
    Posts
    516
    Mentioned
    0 Post(s)
    Quoted
    1 Post(s)

    Default how do you setlength of a matrix?

    exactly as title states, i understand you have to setlength of all arrays, but how do you set length of a matrix? a t2d array... is it same function and it will set length for both the arrays [y][x], or do i have to do it individually somehow? my [x] will be twice the size of [y] so how do i approach this?

  2. #2
    Join Date
    May 2012
    Location
    Glorious Nippon
    Posts
    957
    Mentioned
    47 Post(s)
    Quoted
    481 Post(s)

    Default

    You just iterate through each row:
    Simba Code:
    procedure Test();
    const
      ROWS = 3;
      COLS = 6;
    var
      i: Int32;
      Matrix: T2DIntegerArray; //or Array of Array of Int32;
    begin
      SetLength(Matrix, ROWS);
      for i := 0 to High(Matrix) do
        SetLength(Matrix[i], COLS);
    end;
    The result is a 3x6 matrix.

    I think you can switch rows and columns as long as you keep track of which system you're using.
    Last edited by Citrus; 03-15-2019 at 04:00 AM.

  3. #3
    Join Date
    Feb 2008
    Posts
    516
    Mentioned
    0 Post(s)
    Quoted
    1 Post(s)

    Default

    so setlength (var) sets length of first array and setlength (var[x]) sets length of the 2nd array of array x?

    beautiful, didnt get the results i wanted but im gonna fuck around with it, just tested it out and worked perfectly, thank you for such a quick response
    Last edited by Feroc1ty; 03-15-2019 at 04:02 AM.

  4. #4
    Join Date
    Nov 2011
    Location
    England
    Posts
    3,057
    Mentioned
    287 Post(s)
    Quoted
    1084 Post(s)

    Default

    Quote Originally Posted by Citrus View Post
    You just iterate through each row:
    Simba Code:
    procedure Test();
    const
      ROWS = 3;
      COLS = 6;
    var
      i: Int32;
      Matrix: T2DIntegerArray; //or Array of Array of Int32;
    begin
      SetLength(Matrix, ROWS);
      for i := 0 to High(Matrix) do
        SetLength(Matrix[i], COLS);
    end;
    The result is a 3x6 matrix.

    I think you can switch rows and columns as long as you keep track of which system you're using.
    SetLength does this internally. It will accept a parameter for each dimension.

    Simba Code:
    SetLength(Matrix, 3, 6);
    Last edited by Olly; 03-15-2019 at 10:19 PM.
    <Olly> wtf slacky
    <Olly> this looks like windows
    <Olly> not ubuntu
    <slacky> WHAT DIDN'T YOU GET ABOUT: <slacky> anyways. later
    <slacky> do I have to log of irc to get to play MC?
    <slacky> That sounds like a plan
    * slacky has quit (Quit: Leaving)


Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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