Probably stupid question about Table input from .csv file

edited April 2016 in Questions about Code

Hi all. new to Processing. I'm trying to input a simple numeric array and seemingly missing something. The CSV file I'm trying to input (which lives in a file called graphA.csv in the appropriate directory) is:

1, 0, 0, 1, 0, 1
0, 1, 1, 0, 0, 0
0, 0, 0, 0, 1, 0
0, 0, 0, 0, 1, 0
0, 0, 0, 0, 0, 0
0, 0, 0, 0, 0, 1

Here's the code...

Table graphA;
int graphOrder;
int r;
int c;
int value;

void setup() {
  graphA = loadTable("graphA.csv", "csv");
  graphOrder = graphA.getRowCount();

  for (r = 0; r < graphOrder; r = r+1) {
    for (c = 0; c < graphOrder; c = c+1) {
      value = graphA.getInt(r, c);
      print(value + ", ");
    }
    println(" ");
  }
}

When I run this I get

1, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,

(I know the ","s are messed up - forgive me.) I suspect I'm missing something about either loadTable() or .getInt(), but an hour spent with the documentation does not reveal my error to me. Can someone help me with this?

Thanks. Apologies for what must be a very basic question...

Tagged:

Answers

  • Answer ✓

    Answering my own question, which it turns out WAS stupid in the sense that it's a repetition of a lesson I thought I'd learned 30 years ago...

    It turns out that .csv files should not contain spaces before or after the commas.

    All's well.

Sign In or Register to comment.