Skip to content

Commit

Permalink
More generic input format for kmeans: just comma- or space-separated.
Browse files Browse the repository at this point in the history
  • Loading branch information
e-n-f committed Mar 3, 2013
1 parent 8841283 commit 67fb6c7
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions kmeans.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,18 +101,18 @@ public static void main(String[] argv) {

int here = 0;
int line = 0;
int nfields = 0;
for (int i = 0; i < used; i++) {
if (buf[i] == '\n') {
String[] fields = new String(buf, here, i - here).split(" ");
String[] ao = fields[3].split(",");

double lat = Double.parseDouble(ao[0]);
double lon = Double.parseDouble(ao[1]);

data[line] = new double[2];
String[] fields = new String(buf, here, i - here).split("[ ,]");
if (nfields == 0) {
nfields = fields.length;
}
data[line] = new double[nfields];

data[line][0] = lat;
data[line][1] = lon;
for (int j = 0; j < nfields; j++) {
data[line][j] = Double.parseDouble(fields[j]);
}

here = i + 1;
line++;
Expand Down

0 comments on commit 67fb6c7

Please sign in to comment.