This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2009-08-22 10:18:10

tibongko
Scratcher
Registered: 2009-08-18
Posts: 3

Matrices using List

Here's my steps in simulating a matrix using a list
1. use a variable to store the maximum number of elements of your matrix, say mx
2. use a variable to store the maximum number of rows of your square matrix, say n
3. create a list, say mat; variables for row, col and val
4. delete all of mat
5. ask "Maximum Matrix/Array index" and wait
6. set mx to answer
7. repeat mx
         add 0 to mat
8. try this, change number to text/string
    replace item 7 of mat with "string"
9. ask "Matrix Dimension" and wait
10. set n to answer
11. set row to 0
12. forever if not row = Q
      ask "Row? [Q] to quit" and wait
      set row to answer
      if not row = Q
          ask "Col?" and wait
          set col to answer
          ask "Value to Store?" and wait
          set val to answer
          replace item (((row - 1) * n ) + col) of mat with val

To access the values in row, col of mat use the above equation
item (((row-1)*n) + col) of mat

created a list of 9999 elements equivalent to about 100 rows by 100 cols matrix. don't know the limit of the number of elements of a list though?

Offline

 

Board footer