reference sub-sections of multi-dimensional arrays
hi all ... this is my first post to the list. so, as you would guess, i'm new to chuck. the question ... i'm working on a class with following functionality: serial 12 tone row in > calculate a 12 tone matrix (2D array) > lookup indexed rows (transposition) and/or lookup indexed columns (inversion) > output lookups as 1D arrays the row (x) part is simple: array2D[ row# ] @=> int array1D[]; but, is it possible to reference the y subsection of a 2D array? i know i could do it with a function i.e.: int i[12]; fun void invrton ( int y ) { for (0 => int x; x < 12; x++) { toneRow.matrix[x][y] => i[x]; } } invrton(1); this will assign i[] as values of column i(1), but is there a way w/o the function? i'll most likely put both lookups in the public twlvTone class so the patterns can be accessed by shered-ed instruments. anyway ... here's the full code: public class twlvTone { int matrix[12][12]; fun void setMatrix ( int p0[] ) { for (0 => int x; x < 12; x++) { for (0 => int y; y < 12; y++) { (p0[x] + ((12 - p0[y]) % 12)) % 12 => matrix[y][x]; } } } } twlvTone toneRow; toneRow.setMatrix( [0, 11, 7, 8, 3, 1, 2, 10, 6, 5, 4, 9] ); <<< toneRow.matrix[0][5] >>>; toneRow.matrix[1] @=> int t1[]; <<< t1[11] >>>; thanks, eli
2008/4/29 eli queen
hi all ... this is my first post to the list. so, as you would guess, i'm new to chuck.
Hi, Eli! this will assign i[] as values of column i(1), but is there a way w/o the
function?
I think this is the core question, right? I don't think so, I think you need a function. The thing is that 2d arrays can be seen as a "array of arrays" or a array where every element is a array as well. Returning one element (a 1d array) is easy but returning a element from every element is more complicated and hence needs a function. There is, BTW, a real difference between "assignment" and copying a array element by element, your function here copies. Hope that clarifies things a bit? Yours, Kas.
participants (2)
-
eli queen
-
Kassen