2

Im trying to insert some result arrays to a 2d array. but at the end i only get all the 2d arrays with the set of last array i inserted in to the 2d array. when i debug and check the code i found that every time i do this action bmma[il]=number; the bmma array's all arrays changes with the newly assigning values.

here is the full code i implemented.

double[][] newDATA ;
double [][] bmma = new double[100][];

double [] number = new double[12];
int il=0;
  String fname = "newAudio.wav";

  RawAudioFileStream rawAudio = new RawAudioFileStream(fname);
  StreamHeader mh = mfccm.init(rawAudio.getHeader());
  MatrixFileStream out = new MatrixFileStream(fname + ".txt", true);
  out.setMultiLine(true);
  out.setHeader(mh);


  while (true) {
    StreamFrame f = mfccm.process(rawAudio.recvFrame());

    if (f == null) {
      break;
    }

    if(((MatrixHeader.MatrixFrame)f).data != null){

      for (int i=0;i<12;i++){

        newDATA=((MatrixHeader.MatrixFrame)f).data;
        number[i]=newDATA[i][0];

      }

      bmma[il]=number;
      il++;
    }

Any help will be highly appreciated to overcome this issue.

1 Answer 1

1

You only have one array assigned to number (the one you instantiate here - double [] number = new double[12];), and you assign this array multiple times to the bmma 2D array, so all rows of the 2D arrays will be identical.

You should create a new array for each row of the 2D array :

  number = new double[12];
  for (int i=0;i<12;i++){

    newDATA=((MatrixHeader.MatrixFrame)f).data;
    number[i]=newDATA[i][0];

  }

  bmma[il]=number;
Sign up to request clarification or add additional context in comments.

1 Comment

I cant even realise i did this simple mistake :(. thanks alot for the help. working on a heavy deadline no words to say.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.