Skip to content

Instantly share code, notes, and snippets.

@ats
Created May 2, 2010 15:05
Show Gist options
  • Save ats/387185 to your computer and use it in GitHub Desktop.
Save ats/387185 to your computer and use it in GitHub Desktop.
/* May 1 2010
Processing code to read delimited data from a file and load columns
into arrays.
*/
BufferedReader reader;
String[] lines, row;
int i, j, sumColumn;
String[][] data = new String[7][32]; // adjust to array size
void setup() {
// do regular setup stuff
// ...
// read data file into the 'lines' array
lines = loadStrings("FILE.txt");
// split lines array into a two-dimensional 'data' array
for (i = 0; i < lines.length; i++) {
lines[i] = trim(lines[i]);
row = split(lines[i], "\t");
for (j = 0; j < row.length; j++) {
data[j][i] = row[j];
}
}
} // end void setup
// Pass desired column to a function that does...
int[] dataColumn = new int[lines.length];
for (i=0; i < lines.length-1; i++) {
dataColumn[i] = int(data[column][i+1]);
}
// Then deal with dataColumn as desired
// Could handle row-by-by-row data similarly
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment