We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › Multidimentionnal Arrays
Page Index Toggle Pages: 1
Multidimentionnal Arrays (Read 450 times)
Multidimentionnal Arrays
Oct 22nd, 2005, 12:14pm
 
Hello,

I would like to remove some inner parts of a multi dimentionnal Array but I don't find the way to use .shorten or anything with them.

Example : I have a Array A[25][2] and I'd like to remove the A[12][0] and A[12][1]. I don't care about the order of the resulting Array.
I thought I could do something like this :
Tabl = concat(subset(Tabl,a),subset(Tabl.shorten,a)); (for 1-D Arrays)
But I can't apply this to A[][].

I you know how to help, please do.
thanks,
SeveM
Re: Multidimentionnal Arrays
Reply #1 - Oct 22nd, 2005, 2:10pm
 
how about this:

Code:
float a[][];

void setup() {
a=new float[25][2];

for(int i=0; i<a.length; i++)
for(int j=0; j<a[0].length; j++) a[i][j]=i*2+j;

printArray();
deleteIndex(12);
printArray();
}

void deleteIndex(int id) {
int length1=a.length;
int length2=a[0].length;

float tmp[][]=new float[length1-1][length2];
int cnt=0;
for(int i=0; i<length1; i++) if(i!=id) {
for(int j=0; j<length2; j++) tmp[cnt][j]=a[i][j];
cnt++;
}
a=tmp;
}

void printArray() {
String s;
println("\nContents of array: ");
for(int i=0; i<a.length; i++) {
s=i+":\t";
for(int j=0; j<a[0].length; j++) s+=" "+a[i][j];
println(s);
}
}
Page Index Toggle Pages: 1