0

Here the following code

public static double variance (float[] ListTrouverVariance)

MatCovariance.set(i, j, variance("x"+i));

My "x1" is an array of float and I would like to use as a parameter of variance but I have also another array called "x2" , so I would like to do it with a loop.

I can't do it the way i'm trying because the function is expecting an array and not a string, so i'm looking for a kind of cast.

Simon
  • 3
  • 1
  • 1
    You can't cast strings to names of program variables. Such names are entities that exists only at compile time, and you cannot use strings and integers to create them at run-time, during the program execution. You should try a completely different approach. – Renzo Jan 03 '16 at 17:46

1 Answers1

0

If you have multiple float array's then either you push them onto another array or list and use it.

List<float[]> trouverVarianceList = ...;
trouverVarianceList.add(...);//..

And then use it like:

for (int i=0; i<trouverVarianceList.size();i++) {
    MatCovariance.set(i, j, variance(trouverVarianceList.get(i)));
}
SMA
  • 36,381
  • 8
  • 49
  • 73