Error reading ArrayIndexOutOfBoundsException: 0
in
Programming Questions
•
11 months ago
I'm working on representing a set of data in the form of ellipses based on averages and standard deviations.
I worked out the averages in Edexcel, but there are a few values that fall outside the boundary I'm hoping to set (I will set those boundaries after this issue is resolved), so I will need the average values figured out in Processing.
Can someone please tell me why I'm getting the above error reading and how I can fix it?
- String[] lines;
- float[] AX, AY, AZ, GX, GY, GZ;
- float scalar = 80;
- float averageAX, averageAY, averageAZ = 0.0;
- float averageGX, averageGY, averageGZ = 0.0;
- void setup() {
- size(1050, 500, P3D);
- colorMode(HSB);
- background(100);
- smooth();
- noLoop();
- lines = loadStrings("imu-sensor-data-mconduct-new.csv");
- AX = new float[0];
- AY = new float[0];
- AZ = new float[0];
- GX = new float[0];
- GY = new float[0];
- GZ = new float[0];
- }
- void draw() {
- translate(0, height/2);
- float sumAX = 0;
- float sumAY = 0;
- float sumAZ = 0;
- float sumGX = 0;
- float sumGY = 0;
- float sumGZ = 0;
- for (int k = 0; k < lines.length; k++) {
- String[] pieces = split(lines[k], ',');
- for (int i = 0; i < pieces.length; i++) {
- AX[0] = (float(pieces[1]));
- AY[0] = (float(pieces[2]));
- AZ[0] = (float(pieces[3]));
- GX[0] = (float(pieces[4]));
- GY[0] = (float(pieces[5]));
- GZ[0] = (float(pieces[6]));
- sumAX += AX[i];
- sumAY += AY[i];
- sumAZ += AZ[i];
- sumGX += GX[i];
- sumGY += GY[i];
- sumGZ += GZ[i];
- averageAX = sumAX/3442;
- averageAY = sumAY/3442;
- averageAZ = sumAZ/3442;
- averageGX = sumGX/3442;
- averageGY = sumGY/3442;
- averageGZ = sumGZ/3442;
- smooth();
- fill(0);
- ellipse(150, averageAX, 5, 5);
- ellipse(300, averageAY, 5, 5);
- ellipse(450, averageAZ, 5, 5);
- ellipse(600, averageGX, 5, 5);
- ellipse(750, averageGY, 5, 5);
- ellipse(900, averageGZ, 5, 5);
- }
- }
- }
Cheers,
Oskar
1