Find column max from a 2d array
in
Programming Questions
•
2 years ago
hi, newbie here so i guess it is a simple question.
i loaded a tab delimited csv file (panel) in a 2d array and i want to find the max value of the second column (actually of columns but that is step 2). As i have understood, max() takes only the name of the array so i create an float array (toFind) in order to find it but it does not work...
here is what i have done
the strange thing is when i use max() it prints the values of the column 1, whereas when i use min() i prints only zeros...
any ideas?
i loaded a tab delimited csv file (panel) in a 2d array and i want to find the max value of the second column (actually of columns but that is step 2). As i have understood, max() takes only the name of the array so i create an float array (toFind) in order to find it but it does not work...
here is what i have done
- String [] data;
- String [][] csv;
- float c;
- void setup(){
- size(100,100);
- data=loadStrings("crime.txt");
- csv=new String [data.length][9];
- for (int i=0; i<data.length; i++){
- String [] temp=new String [data.length];
- temp=split(data[i], "\t");
- for (int j=0; j<9; j++){
- csv[i][j]=temp[j];
- }
-
- }
- for (int i=1; i<data.length; i++){
- float [] toFind=new float [data.length];
- toFind[i]=Float.parseFloat(csv[i][1]);
- c=max(toFind);
- print(c);
- }
- }
the strange thing is when i use max() it prints the values of the column 1, whereas when i use min() i prints only zeros...
any ideas?
1