D daveinhull Active Member Licensed User Longtime User Jul 6, 2020 #1 Hi, Is it possible to have two dimensional arrays in B4R? I've search the forum, but nothing comes up for B4R and the IDE/Compiler says No! Thanks Dave
Hi, Is it possible to have two dimensional arrays in B4R? I've search the forum, but nothing comes up for B4R and the IDE/Compiler says No! Thanks Dave
thetahsk Active Member Licensed User Longtime User Jul 7, 2020 #2 daveinhull said: ... Click to expand... You have to flatten the 2D matrix, create your usual 1D Array and use a mapping function to access the elements as a 2D array. Row, Col to array index Hello, I have 64 rows, 16 cols of 1 byte LCD, I use 1024 bytes array to store a bitmap image. in this loop I want to read array element represents col byte(convert Row, Col to array index). any Ideas? For Row = 0 To 63 For Col = 0 To 15 Index = 'row and col something... www.b4x.com Treating a 1D data structure as 2D grid I am working with a native class that represents a 2D image as a 1D array. If you want to change one pixel, for example, you need to now how to derive the index from the x,y coordinates. So, let's... softwareengineering.stackexchange.com Upvote 0
daveinhull said: ... Click to expand... You have to flatten the 2D matrix, create your usual 1D Array and use a mapping function to access the elements as a 2D array. Row, Col to array index Hello, I have 64 rows, 16 cols of 1 byte LCD, I use 1024 bytes array to store a bitmap image. in this loop I want to read array element represents col byte(convert Row, Col to array index). any Ideas? For Row = 0 To 63 For Col = 0 To 15 Index = 'row and col something... www.b4x.com Treating a 1D data structure as 2D grid I am working with a native class that represents a 2D image as a 1D array. If you want to change one pixel, for example, you need to now how to derive the index from the x,y coordinates. So, let's... softwareengineering.stackexchange.com
E emexes Expert Licensed User Longtime User Jul 7, 2020 #3 thetahsk said: a mapping function Click to expand... or roll your own extra dimension, eg for a 12 x 16 array: Code: Copy Dim A(12 * 16) 'equivalent to Dim A(12, 16) ie both allocate 192 elements A(5 * 16 + 8) = 42 'equivalent to A(5, 8) = 42 For I = 0 to 12 - 1 For J = 0 to 16 - 1 Log("A(" & I & ", " & J & ") = " & A(I * 16 + J)) 'equivalent to ... A(I, J) Next Next edit: I saw "mapping function" and thought this meant B4X Map container and massive performance hit, but in retrospect "I * 16 + J" could also be called a mapping function and perhaps my performance nerve fired unnecessarily ? Last edited: Jul 7, 2020 Upvote 0
thetahsk said: a mapping function Click to expand... or roll your own extra dimension, eg for a 12 x 16 array: Code: Copy Dim A(12 * 16) 'equivalent to Dim A(12, 16) ie both allocate 192 elements A(5 * 16 + 8) = 42 'equivalent to A(5, 8) = 42 For I = 0 to 12 - 1 For J = 0 to 16 - 1 Log("A(" & I & ", " & J & ") = " & A(I * 16 + J)) 'equivalent to ... A(I, J) Next Next edit: I saw "mapping function" and thought this meant B4X Map container and massive performance hit, but in retrospect "I * 16 + J" could also be called a mapping function and perhaps my performance nerve fired unnecessarily ?
thetahsk Active Member Licensed User Longtime User Jul 7, 2020 #4 emexes said: ... my performance nerve fired unnecessarily ? Click to expand... Your "friendly fire" with fluffy marshmallows has not harmed my bulletproof vest. Upvote 0
emexes said: ... my performance nerve fired unnecessarily ? Click to expand... Your "friendly fire" with fluffy marshmallows has not harmed my bulletproof vest.
E emexes Expert Licensed User Longtime User Jul 7, 2020 #5 thetahsk said: Your "friendly fire" with fluffy marshmallows has not harmed my bulletproof vest. Click to expand... fired as in neuron activation, not as in firearm ? your reply was great except for my instinctive reflex misreaction to Map substitute for Array Upvote 0
thetahsk said: Your "friendly fire" with fluffy marshmallows has not harmed my bulletproof vest. Click to expand... fired as in neuron activation, not as in firearm ? your reply was great except for my instinctive reflex misreaction to Map substitute for Array
D daveinhull Active Member Licensed User Longtime User Jul 7, 2020 #6 Thanks Folk, I ended up doing it with a mapping function into a single dimension array. Is there any particular reason why we can't have two or multiple dimensional arrays in B4R? Thanks Dave Upvote 0
Thanks Folk, I ended up doing it with a mapping function into a single dimension array. Is there any particular reason why we can't have two or multiple dimensional arrays in B4R? Thanks Dave