We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello,
I have a table stored as a CSV file:
Event1 Event2 Percent Frequency
1 2 0.5 100
1 5 0.48 80
5 7 0.36 55
I'd like to be able to create a 2D array with the event columns, and 2 other 1D arrays from the percent and frequency columns. Something similar was done in another post (http://forum.processing.org/two/discussion/6668/how-to-convert-a-csv-file-into-arrays-one-1d-and-one-2d), but instead of a 2D array, a PVector array was used. Is there any way to do this by populating a 2D array?
I've been able to read the file, but I'm not sure how to populate the arrays:
int [][] events;
int colCount = 0;
int rowCount = 0;
float [] perc;
int [] freq;
String file = "file.csv";
void setup(){
Table table = loadTable(file, "header, csv");
for (TableRow row : table.rows()){
int event1 = row.getInt("Event1");
int event2 = row.getInt("Event2");
float percent = row.getFloat("Percent");
int frequency = row.getInt("Frequency");
}
Thanks in advance!
Answers
Perfect, thanks for your help GoToLoop! I'm still quite new to Processing, so I apologise for my crappy code. I'm going to have a close look to understand this and learn from it ;)
Hi, one more question, as an extension to this: I have drawn a set of rectangles using a for loop.
How can I colour these rectangles using values from the 2D array? I would assume that I'd have to read through the array to get the values, then use an if statement to colour the rectangles (e.g. if value=1, colour red). I haven't been able to find anything in my searches.