|
Author |
Topic: resampling data *ahh why doesn't this work (Read 275 times) |
|
K1diN5An3
|
resampling data *ahh why doesn't this work
« on: Oct 12th, 2004, 7:15am » |
|
trying to resample this data. printed out X and Y points in array form, using a continuous line drawing program, want to keep the form of the drawing but standardize the number of points so then will be able to interpolate between different drawings. This code keeps throwing an array out of bounds exception. Obviously there some error in my math. driving my crazy. glup. Help! int data[][][] = new int[1][89][2]; int resampled [][][] = new int[1][23][2]; int npoints = 89; int standard = 20; int interval; void setup(){ size(400,400); fillMyArrayData(); interval = npoints/standard; for(int i = 0; i <= npoints; i+=interval) { print(data[0][i][0]); print(" "); //prints 23 numbers resampled[0][i][0] = data[0][i][0]; // array out of bounds here ahh why?.. //resampled[0][i][1] = data[0][i][1]; } for(int j =0; j <= 22; j++) { //trying to print out the resampled X and Y coords so I can use them again. //print(resampled[0][j][0]); //print(resampled[0][j][1]); } } void loop() { } void fillMyArrayData(){ //----- X and Y coordinates data[0][0][0]=297;data[0][0][1]=309;data[0][1][0]=297;data[0][1][1]=309;data[0][2][0]=297;data[0][2][1]=309;data[0][3][0]=297;data[0][3][1]=309;data[0][4][0]=297;data[0][4][1]=309;data[0][5][0]=298;data[0][5][1]=307;data[0][6][0]=298;data[0][6][1]=307;data[0][7][0]=298;data[0][7][1]=304;data[0][8][0]=299;data[0][8][1]=296;data[0][9][0]=298;data[0][9][1]=285;data[0][10][0]=298;data[0][10][1]=285;data[0][11][0]=297;data[0][11][1]=270;data[0][12][0]=297;data[0][12][1]=270;data[0][13][0]=294;data[0][13][1]=249;data[0][14][0]=294;data[0][14][1]=249;data[0][15][0]=285;data[0][15][1]=220;data[0][16][0]=285;data[0][16][1]=220;data[0][17][0]=279;data[0][17][1]=203;data[0][18][0]=279;data[0][18][1]=203;data[0][19][0]=274;data[0][19][1]=190;data[0][20][0]=274;data[0][20][1]=190;data[0][21][0]=269;data[0][21][1]=180;data[0][22][0]=266;data[0][22][1]=174;data[0][23][0]=261;data[0][23][1]=165;data[0][24][0]=261;data[0][24][1]=165;data[0][25][0]=253;data[0][25][1]=151;data[0][26][0]=253;data[0][26][1]=151;data[0][27][0]=243;data[0][27][1]=138;data[0][28][0]=243;data[0][28][1]=138;data[0][29][0]=236;data[0][29][1]=131;data[0][30][0]=233;data[0][30][1]=128;data[0][31][0]=227;data[0][31][1]=124;data[0][32][0]=227;data[0][32][1]=124;data[0][33][0]=227;data[0][33][1]=124;data[0][34][0]=227;data[0][34][1]=124;data[0][35][0]=206;data[0][35][1]=109;data[0][36][0]=206;data[0][36][1]=109;data[0][37][0]=206;data[0][37][1]=109;data[0][38][0]=206;data[0][38][1]=109;data[0][39][0]=206;data[0][39][1]=109;data[0][40][0]=206;data[0][40][1]=109;data[0][41][0]=168;data[0][41][1]=93;data[0][42][0]=168;data[0][42][1]=93;data[0][43][0]=153;data[0][43][1]=93;data[0][44][0]=143;data[0][44][1]=95;data[0][45][0]=143;data[0][45][1]=95;data[0][46][0]=129;data[0][46][1]=101;data[0][47][0]=123;data[0][47][1]=104;data[0][48][0]=116;data[0][48][1]=110;data[0][49][0]=115;data[0][49][1]=112;data[0][50][0]=107;data[0][50][1]=122;data[0][51][0]=98;data[0][51][1]=133;data[0][52][0]=98;data[0][52][1]=133;data[0][53][0]=80;data[0][53][1]=164;data[0][54][0]=73;data[0][54][1]=182;data[0][55][0]=67;data[0][55][1]=201;data[0][56][0]=67;data[0][56][1]=201;data[0][57][0]=67;data[0][57][1]=201;data[0][58][0]=67;data[0][58][1]=229;data[0][59][0]=82;data[0][59][1]=264;data[0][60][0]=82;data[0][60][1]=264;data[0][61][0]=110;data[0][61][1]=285;data[0][62][0]=110;data[0][62][1]=285;data[0][63][0]=132;data[0][63][1]=292;data[0][64][0]=132;data[0][64][1]=292;data[0][65][0]=132;data[0][65][1]=292;data[0][66][0]=204;data[0][66][1]=282;data[0][67][0]=204;data[0][67][1]=282;data[0][68][0]=204;data[0][68][1]=282;data[0][69][0]=259;data[0][69][1]=253;data[0][70][0]=259;data[0][70][1]=253;data[0][71][0]=259;data[0][71][1]=253;data[0][72][0]=259;data[0][72][1]=253;data[0][73][0]=259;data[0][73][1]=253;data[0][74][0]=259;data[0][74][1]=253;data[0][75][0]=280;data[0][75][1]=221;data[0][76][0]=280;data[0][76][1]=221;data[0][77][0]=280;data[0][77][1]=221;data[0][78][0]=280;data[0][78][1]=221;data[0][79][0]=280;data[0][79][1]=221;data[0][80][0]=280;data[0][80][1]=221;data[0][81][0]=282;data[0][81][1]=207;data[0][82][0]=282;data[0][82][1]=207;data[0][83][0]=282;data[0][83][1]=207;data[0][84][0]=282;data[0][84][1]=207;data[0][85][0]=282;data[0][85][1]=207;data[0][86][0]=282;data[0][86][1]=207;data[0][87][0]=282;data[0][87][1]=207;data[0][88][0]=282;data[0][88][1]=207;}
|
|
|
|
K1diN5An3
|
Re: resampling data *ahh why doesn't this work
« Reply #1 on: Oct 12th, 2004, 10:53am » |
|
at times i = values higher than 23. by adding another counter that increments by 1, one can avoid an array out of bound exception
|
|
|
|
fjen
|
Re: resampling data *ahh why doesn't this work
« Reply #2 on: Oct 12th, 2004, 4:05pm » |
|
uff, you hacked the board! hihi. it's not your data array that throws the exception, it's the resampled array: npoints is 89, resampled is [1][23][2] you are going from 0 to npoints: resampled [0][i][0] <-- there's the problem.
|
|
|
|
|