there are ( like i show you ) nested datasets,
but in CSV and EXCEL and SQL it has to done by INDEXing
as there can not be a syntax [a,b,c],[d,e,f] in a CSV file!
or did you try to load it into EXCEL?
now that syntax ( what you might see for 2 dim arrays )
is replaced by the index columns what makes you free
for even more dimensions, BUT basic rule:
the number of [f1,f2,f3,f4,f5] here 5
must stay same throughout the database.
in SQL the index columns would actually be in separate tables
data: ( indexed main table: idx,f1,f2,f3,f4,f5 )
1,a,b,c,d,e
2,f,g,h,i,j
3
4
5
6
table dimension: idx, major, minor, main_idx
1,0,0,0
2,0,1,1
3,0,2,2
4,1,0,3
5,1,1,4
6,1,2,5
7,2,0,6
in a ( for spreadsheet valid ) CSV file
( and like you have started it for JSON also )
you would do like i show
major, minor, f1,f2,f3,f4,f5
and then there is no reading / loading problem ( as there or no “” )
the CSV and code i show is functioning,
and as mentioned your thinking in multi dim array needs a little
more code like
float get_val(int major, int minor) {}
but that is just using the already loaded table.
like
click
// accessing nested values in a table
// https://discourse.processing.org/t/accessing-nested-values-in-a-table/9761
// v0.2 function (major,minor,fx)
/*
/data/data.csv
_______________________
major, minor,A,B,C,D,E
0,0,40.65, 20.30, 120.92, 86.12, 99.33
0,1,10.35, 90.10, 10.52, 1.12, 59.3
0,2,10.65, 62.10, 12.12, 96.23, 19.3
1,0,96.37, 67.13, 312.62, 87.11, 87.18
1,1,90.94, 41.04, 63.01, 9.10, 30.3
1,2,11.98, 99.01, 41.30, 16.04, 10.4
2,0,11.88, 12.98, 182.22, 13.84, 81.09
2,1,50.35, 10.10, 10.52, 8.12, 91.3
2,2,88.51, 21.66, 81.13, 36.13, 97.3
________________________
*/
Table data;
String data_fn = "data/data.csv";
int dc = 60, dx = 10, dr =20, posx, posy;
void setup() {
size(500, 500);
data = loadTable(data_fn, "header");
}
void draw() {
background(80, 80, 0);
for (int c =0; c < data.getColumnCount(); c++) text(data.getColumnTitle(c), dx+c*dc, dr); // data Column Header
for (int r = 0; r < data.getRowCount(); r++) for (int c =0; c < data.getColumnCount(); c++) { // data
posx = dx+c*dc;
posy = (r+1)*dr;
text(data.getString(r, c), posx, dr + posy); // data cell content
}
}
float get_matrix(int major, int minor, int fcol) {
String ma = str(major); // findRows uses string??
float result=-9999;
for ( TableRow row : data.findRows(ma, 0) ) {
if ( row.getInt(1) == minor ) result = row.getFloat(2+fcol); // column like "A" as 0 in col 2
}
return result;
}
void print_matrix() {
for ( int i = 0; i < 3; i++ ) for ( int j = 0; j < 3; j++ ) {
for ( int k = 0; k < 5; k++ ) print(" ["+i+","+j+","+k+"]: "+ get_matrix(i, j, k) );
println();
}
}
void keyPressed() {
if ( key == 'p' ) print_matrix();
}