I have the following problem, I imported a file .csv into a 2d array called csv.
This has null entries in each odd row, therefore just even rows, starting from 0 (0, 2, 4, ... 606) are filled with data relevant for me
so, the size of the 2d array is 609, 560 and they come from printing csv.length and csv[1].length
I need to have a file whose size is 304x561, and I call it csv2.
However, the following code gives me an error
String rows[] = loadStrings("cit2.txt");
String [][] csv; // initialize csv file
String [][] csv2; // initialize reduced csv file
int csvWidth=0;
//calculate max width of csv file
for (int i=0; i < rows.length; i++) {
String [] columns = split(rows[i],'\t');
if (columns.length>csvWidth){
csvWidth=columns.length;
}
}
//create csv array based on # of rows and columns in csv file
csv = new String [rows.length][csvWidth];
//parse values into 2d array
for (int i=0; i < rows.length; i++) {
String [] temp = new String [rows.length];
//strDelimiter = (strDelimiter || ",");
temp= split(rows[i], '\t');
for (int j=0; j < temp.length; j++){
csv[i][j]=temp[j];
}
}
//test
println(csv[604][0]);
println(csv.length);
println(csv[0].length);
int row = csv.length;
println(((row-1)/2));
int newrow = 0;
int col = csv[0].length;
//int row = csv.length;
csv2 = new String [((row-1)/2)-1][col];
for (int c=0; c <csv[0].length; c++)
{
for(int r=0; r<(csv.length)-1; r = r+2)
{
String temp = csv[r][c];
newrow = newrow +1;
csv2[newrow][c]= temp;
}
}
any idea?