Results 1 to 7 of 7

Thread: Row major order

  1. #1
    Member REDEBOLT's Avatar
    Join Date
    Dec 2006
    Location
    Pickerington, Ohio, USA
    Age
    87
    Posts
    62
    Rep Power
    24

    Row major order

    Hi All,

    I am tring to load a matrix in row major order, but I get an error on
    Array Assign "Invalid delimiter."

    c.f. post.

    Must I load a matrix and then transpose it?

    Regards,
    Bob

  2. #2
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,128
    Rep Power
    732
    Hi!,

    to assign matrix in row order, you just need to use square brackets on assignment. I just tested it in ThinBASIC 1.8.8.0:
    Uses "Console"
    
    Dim myMatrix(3, 3) As Ext
    
    myMatrix = [ 1, 2, 3,
                 4, 5, 6,
                 7, 8, 9 ]
                 
    PrintL myMatrix(1, 1), myMatrix(1, 2), myMatrix(1, 3)               
    PrintL myMatrix(2, 1), myMatrix(2, 2), myMatrix(2, 3)               
    PrintL myMatrix(3, 1), myMatrix(3, 2), myMatrix(3, 3)               
    
    WaitKey
    
    The approach with () mentioned in the referenced post has been replaced with [] last year, this change is also documented in Help file in What's new log.


    Petr
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

  3. #3
    Member REDEBOLT's Avatar
    Join Date
    Dec 2006
    Location
    Pickerington, Ohio, USA
    Age
    87
    Posts
    62
    Rep Power
    24
    Ok, I use square brackets, but get same error:

      Dim arat(14,14) As String
        Array Assign arat() = 
       [1,   1   , "1/2" , "1/3" , "1/4" , "1/5" , "1/6" , "1/7" , "1/8" , "1/9" , "1/10", "1/11", "1/12", "1/13", _
        1, "1/2" , "1/3" , "1/4" , "1/5" , "1/6" , "1/7" , "1/8" , "1/9" , "1/10", "1/11", "1/12", "1/13", "1/14", _
        1, "1/3" , "1/4" , "1/5" , "1/6" , "1/7" , "1/8" , "1/9" , "1/10", "1/11", "1/12", "1/13", "1/14", "1/15", _
        1, "1/4" , "1/5" , "1/6" , "1/7" , "1/8" , "1/9" , "1/10", "1/11", "1/12", "1/13", "1/14", "1/15", "1/16", _
        1, "1/5" , "1/6" , "1/7" , "1/8" , "1/9" , "1/10", "1/11", "1/12", "1/13", "1/14", "1/15", "1/16", "1/17", _
        1, "1/6" , "1/7" , "1/8" , "1/9" , "1/10", "1/11", "1/12", "1/13", "1/14", "1/15", "1/16", "1/17", "1/18", _
        1, "1/7" , "1/8" , "1/9" , "1/10", "1/11", "1/12", "1/13", "1/14", "1/15", "1/16", "1/17", "1/18", "1/19", _
        1, "1/8" , "1/9" , "1/10", "1/11", "1/12", "1/13", "1/14", "1/15", "1/16", "1/17", "1/18", "1/19", "1/20", _
        1, "1/9" , "1/10", "1/11", "1/12", "1/13", "1/14", "1/15", "1/16", "1/17", "1/18", "1/19", "1/20", "1/21", _
        1, "1/10", "1/11", "1/12", "1/13", "1/14", "1/15", "1/16", "1/17", "1/18", "1/19", "1/20", "1/21", "1/22", _
        1, "1/11", "1/12", "1/13", "1/14", "1/15", "1/16", "1/17", "1/18", "1/19", "1/20", "1/21", "1/22", "1/23", _
        1, "1/12", "1/13", "1/14", "1/15", "1/16", "1/17", "1/18", "1/19", "1/20", "1/21", "1/22", "1/23", "1/24", _
        1, "1/13", "1/14", "1/15", "1/16", "1/17", "1/18", "1/19", "1/20", "1/21", "1/22", "1/23", "1/24", "1/25", _
        1, "1/14", "1/15", "1/16", "1/17", "1/18", "1/19", "1/20", "1/21", "1/22", "1/23", "1/24", "1/25", "1/26" ]
    
    Bob

  4. #4
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10
    Dear Bob,

    I'm sorry but row major order is actually supported only fro numeric matrix.
    I will work in order to add it also for all kind of arrays.

    Eros

    PS: added request in support area
    http://www.thinbasic.com/community/project.php?issueid=308

    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  5. #5
    Member REDEBOLT's Avatar
    Join Date
    Dec 2006
    Location
    Pickerington, Ohio, USA
    Age
    87
    Posts
    62
    Rep Power
    24
    Thanks, Eros.

  6. #6
    thinBasic MVPs danbaron's Avatar
    Join Date
    Jan 2010
    Location
    California
    Posts
    1,378
    Rep Power
    152
    ' code -----------------------------------------------------------------------
    Uses "console"
    '-----------------------------------------------------------------------------
    
    Function setmatrix(ByRef b() As String, n As Integer)
    Local s1, s2 As String
    Local i, j As Integer
    
    For i = 1 To %n
    For j = 1 To %n
    s1 = Format$(i, "00")
    s2 = Format$(j, "00")
    b(i,j) = s1 & s2
    Next
    Next
    End Function
    
    '-----------------------------------------------------------------------------
    
    Function printmatrix(ByRef b() As String, n As Integer)
    Local i, j As Integer
    
    For i = 1 To %n
    For j = 1 To %n
    Print b(i,j), " "
    Next
    PrintL
    Next
    PrintL
    End Function 
    
    '-----------------------------------------------------------------------------
    
    Function transmatrix(ByRef b() As String, n As Integer)
    ' Transposes a square matrix in-place.
    
    Integer i, j
    Local temp As String
    
    For i = 1 To n
    For j = i+1 To n
    temp = b(i,j)
    b(i,j) = b(j,i)
    b(j,i) = temp
    Next
    Next
    End Function
    
    '-----------------------------------------------------------------------------
    
    Function TBMain()
    %n = 10
    Local a(%n,%n) As String
    
    setmatrix(a,%n)
    printmatrix(a,%n)
    transmatrix(a,%n)
    printmatrix(a,%n)
    
    WaitKey
    End Function
     
    ' output ---------------------------------------------------------------------
    
     0101   0102   0103   0104   0105   0106   0107   0108   0109   0110
     0201   0202   0203   0204   0205   0206   0207   0208   0209   0210
     0301   0302   0303   0304   0305   0306   0307   0308   0309   0310
     0401   0402   0403   0404   0405   0406   0407   0408   0409   0410
     0501   0502   0503   0504   0505   0506   0507   0508   0509   0510
     0601   0602   0603   0604   0605   0606   0607   0608   0609   0610
     0701   0702   0703   0704   0705   0706   0707   0708   0709   0710
     0801   0802   0803   0804   0805   0806   0807   0808   0809   0810
     0901   0902   0903   0904   0905   0906   0907   0908   0909   0910
     1001   1002   1003   1004   1005   1006   1007   1008   1009   1010
    
     0101   0201   0301   0401   0501   0601   0701   0801   0901   1001
     0102   0202   0302   0402   0502   0602   0702   0802   0902   1002
     0103   0203   0303   0403   0503   0603   0703   0803   0903   1003
     0104   0204   0304   0404   0504   0604   0704   0804   0904   1004
     0105   0205   0305   0405   0505   0605   0705   0805   0905   1005
     0106   0206   0306   0406   0506   0606   0706   0806   0906   1006
     0107   0207   0307   0407   0507   0607   0707   0807   0907   1007
     0108   0208   0308   0408   0508   0608   0708   0808   0908   1008
     0109   0209   0309   0409   0509   0609   0709   0809   0909   1009
     0110   0210   0310   0410   0510   0610   0710   0810   0910   1010
    
    Last edited by danbaron; 27-08-2011 at 07:59.
    "You can't cheat an honest man. Never give a sucker an even break, or smarten up a chump." - W.C.Fields

  7. #7
    thinBasic MVPs danbaron's Avatar
    Join Date
    Jan 2010
    Location
    California
    Posts
    1,378
    Rep Power
    152
    ' code -----------------------------------------------------------------------
    Uses "console"
    '-----------------------------------------------------------------------------
    
    Function setmatrix(ByRef b() As String, n As Integer)
    Local s As String
    Local i,j As Integer
    
    For i = 1 To n
    b(i,1) = "1/01"
    For j = 2 To n
    s = Format$(i+j-2, "00")
    b(i,j) = "1/" & s
    Next
    Next
    End Function
    
    '-----------------------------------------------------------------------------
    
    Function printmatrix(ByRef b() As String, n As Integer)
    Local i, j As Integer
    
    For i = 1 To %n
    For j = 1 To %n
    Print b(i,j), ""
    Next
    PrintL
    Next
    PrintL
    End Function 
    
    '-----------------------------------------------------------------------------
    
    Function TBMain()
    %n = 13
    Local a(%n,%n) As String
    
    setmatrix(a,%n)
    printmatrix(a,%n)
    
    WaitKey
    End Function
    
    ' output ---------------------------------------------------------------------
    
     1/01  1/01  1/02  1/03  1/04  1/05  1/06  1/07  1/08  1/09  1/10  1/11  1/12
     1/01  1/02  1/03  1/04  1/05  1/06  1/07  1/08  1/09  1/10  1/11  1/12  1/13
     1/01  1/03  1/04  1/05  1/06  1/07  1/08  1/09  1/10  1/11  1/12  1/13  1/14
     1/01  1/04  1/05  1/06  1/07  1/08  1/09  1/10  1/11  1/12  1/13  1/14  1/15
     1/01  1/05  1/06  1/07  1/08  1/09  1/10  1/11  1/12  1/13  1/14  1/15  1/16
     1/01  1/06  1/07  1/08  1/09  1/10  1/11  1/12  1/13  1/14  1/15  1/16  1/17
     1/01  1/07  1/08  1/09  1/10  1/11  1/12  1/13  1/14  1/15  1/16  1/17  1/18
     1/01  1/08  1/09  1/10  1/11  1/12  1/13  1/14  1/15  1/16  1/17  1/18  1/19
     1/01  1/09  1/10  1/11  1/12  1/13  1/14  1/15  1/16  1/17  1/18  1/19  1/20
     1/01  1/10  1/11  1/12  1/13  1/14  1/15  1/16  1/17  1/18  1/19  1/20  1/21
     1/01  1/11  1/12  1/13  1/14  1/15  1/16  1/17  1/18  1/19  1/20  1/21  1/22
     1/01  1/12  1/13  1/14  1/15  1/16  1/17  1/18  1/19  1/20  1/21  1/22  1/23
     1/01  1/13  1/14  1/15  1/16  1/17  1/18  1/19  1/20  1/21  1/22  1/23  1/24
    
    Last edited by danbaron; 28-08-2011 at 06:15.
    "You can't cheat an honest man. Never give a sucker an even break, or smarten up a chump." - W.C.Fields

Similar Threads

  1. Row order in matrix filling
    By ErosOlmi in forum thinBasic vaporware
    Replies: 7
    Last Post: 01-09-2011, 02:04
  2. Above all else - order must be maintained!
    By danbaron in forum Shout Box Area
    Replies: 2
    Last Post: 03-06-2011, 05:26
  3. Network byte order
    By Michael Clease in forum thinBasic General
    Replies: 8
    Last Post: 04-10-2007, 11:46

Members who have read this thread: 0

There are no members to list at the moment.

Posting Permissions

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