我试图迭代一个新对象数组,隔离该对象内的值,然后将其存储在一个新数组中,这样我就可以排序并计算值的中位数。我能够隔离浮点值m.BreakUp
但是将它放入breakUp
数组似乎是在逃避我。关于我需要创建什么类型的数组以接受mBreakUp
浮点值的任何想法?
// GLOBAL DATA
sourceType roster[]; // our database of Sources
int nSources=0; // number of Sources
float breakUp[];
void setup() {
size(720,720, P3D);
// load all data, with each record (i.e. text line) as a string
String lines[]= loadStrings("MarriageSuccess-Table-S12.csv");
nSources=lines.length-2;
roster=new sourceType[nSources];
// create "sourceType" objects into database, with the line split by tabs
// ( "\t" == tab , "," == comma , "\n" == carriage return/newline )
for (int i=0; i<nSources; i++) {
roster[i]=new sourceType(lines[i+1].split(","));
println(i.mBreakUp);
}
// running into problem here
for (sourceType i :roster){
breakUp = append(breakUp,i.mBreakUp);
}
}
答案 0 :(得分:0)
所以我想出来了。
我正在错误地初始化breakUp数组。它现在正在运作。
// GLOBAL DATA
sourceType roster[]; // our database of Sources
int nSources=0; // number of Sources
float[] breakUp = new float[0];