Arrays of a class
in
Programming Questions
•
8 months ago
Hi all,
I am trying to create an array of a class but am getting an error code. The code below is supposed to import multiple csv files with file names listed in the list array . Please can you let me know what I have done wrong?
String[] list;
WINCH[] winch;
void setup(){
filelist();
WINCH[] winch =new WINCH[list.length];
for (int n=0 ; n<list.length ; n++ ){
winch[n] = new WINCH(n);
}
}
void filelist(){
//create file list
int starttrack = 4;
int endtrack = 6;
int startwinch = 1;
int endwinch = 4;
int winchquantity = (endtrack-starttrack+1)*(endwinch-startwinch+1);
String[] list = new String [winchquantity];
int index = 0;
for (int tr=starttrack;tr<endtrack+1;tr++) {
for (int wi=startwinch;wi<endwinch+1;wi++){
list[index] = "car_" + tr + "_" + wi +".txt";
index++;
}}
}
class WINCH{
String lines[];
String [][] csv;
int csvWidth=0;
float [] x;
float [] y;
int timesteps;
WINCH(int ind){
//load CSV
int index = ind;
lines = loadStrings(list[index]);
//calculate max width of csv file
for (int i=0; i < lines.length; i++) {
String [] chars=split(lines[i],',');
if (chars.length>csvWidth){
csvWidth=chars.length;
}
timesteps=lines.length-1;
}
//defines variables
csv = new String [lines.length][csvWidth];
x = new float [timesteps];
y = new float [timesteps];
//parse values into csv array
for (int i=0; i < lines.length; i++) {
String [] temp = new String [lines.length];
temp= split(lines[i], ',');
for (int j=0; j < temp.length; j++){
csv[i][j]=temp[j];
}
}
//parse variables to time, position variables
for (int i=0; i < timesteps; i++) {
x[i]=float(csv[i+1][1])*(-1);
y[i]=float(csv[i+1][0]);
}
}}
1