迭代对象数组 - >在新数组中存储属性的浮点值

时间:2014-10-07 00:24:06

标签: arrays processing

我试图迭代一个新对象数组,隔离该对象内的值,然后将其存储在一个新数组中,这样我就可以排序并计算值的中位数。我能够隔离浮点值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);
  }
}

1 个答案:

答案 0 :(得分:0)

所以我想出来了。

我正在错误地初始化breakUp数组。它现在正在运作。

// GLOBAL DATA
sourceType roster[];            // our database of Sources
int       nSources=0;       // number of Sources
float[]   breakUp = new float[0];