Shop OBEX P1 Docs P2 Docs Learn Events
arrays and matrixes — Parallax Forums

arrays and matrixes

jonduncanjonduncan Posts: 40
edited 2007-03-17 21:44 in Propeller 1
can you make matrixes in spin· how do you assign an array or mattrix all at the same time without looping through the array

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2007-03-17 13:04
    Spin has one dimensional arrays. You have to implement higher dimensions by yourself. For example, a 3 x 3 matrix is declared as an array of 9 elements. To access the i'th/j'th element, you'd use "i*3+j" as a subscript.

    You'd have to loop through the array to do an assignment. There's no "syntactic sugar" for matrices.
  • jonduncanjonduncan Posts: 40
    edited 2007-03-17 18:36
    yeah, thanks thats what i am doing now, just wondering if there was an easy way to initialize something.
  • Harrison.Harrison. Posts: 484
    edited 2007-03-17 21:44
    Couldn't you use bytefill / wordfill to initialize the array? I read that it is much more efficient then looping through the array since the interpreter handles it internally.

    For example, I use a 2d array by using the same method as Mike proposed. To init the array with all zeros, I do a bytefill(@buffarray, 0, BUFFLEN). BUFFLEN being the size of the array, and 0 being the value to fill with.
Sign In or Register to comment.