0

I have two classes, MainActivity and HjorthClass.

Please direct your attention to the TestSeizureDetected() at the bottom of MainActivity. Everything else is working fine. When I run testValue.returnVal() I only get the value 1.0. That number does not change regardless the numbers in the string. I have already verified that finalSeizureData is accurate by printing out values at different positions.

String huge is composed of 7681 separate values, and is not included in this. The issue lies in my Hjorthclass, but I cannot figure out where it is or why returnVal only returns 1.0.

*EDIT:*Only relevant code is showing. Since code has been edited and cut down in size, do not point out Syntax errors in MainActivity. Thank you.

public class MainActivity extends Activity implements LocationListener{
    public double[][] finalSeizureData= new double[7681][1];

    public HjorthClass testValue;


    public void TestSeizureDetected()
    {
        String[] temp = huge.split("\\s+");
        double[] convert = new double[temp.length];
        for(int y = 0; y<convert.length; y++)
        {
            convert[y]= Double.parseDouble(temp[y]);
        }
        for(int i = 0; i<convert.length;i++)
        {
            for(int j = 0; j<1;j++)
            {
                finalSeizureData[i][j] = convert[i];
            }
        }
        testValue = new HjorthClass(finalSeizureData);
            textResult.setText("Value"+ testValue.returnVal());
        if(testValue.returnSum()== true)
        {
            textResult.setText("Seizure has been detected in Text File");
        }

    }

}

Hjorth Class

public class HjorthClass extends Activity{
public double [][]Active;
public int height;
public int width;
public double [][] m0;
public double [][] threshold;
public double sum;
public double []temp;

//check length of height
public HjorthClass (double [][]Active)
{
    height = Active[0].length;
    width = Active[1].length;
    m0 = new double[height][width];
    threshold= new double[height][width];
    sum = 0;


    for(int i = 0; i<height; i++)// Original moving average - is used for Activity
    {
        if(i == 0)
        {
            m0[0][0] = Active[i][i];
        }
        else
        {
          for(int j =0; j < width; j++) 
          {
              m0[i][j] = Active[i][j];
          }
        }       
    }



    for(int i = 0; i<height; i++)
    {
          for(int j =0; j < width; j++) 
          {
            if(m0[i][j] >= 1 )
            {
              threshold[i][j] = 1;
            }
            else
            {
              threshold[i][j]=0;
            }
          } 
    }   

    for(int i = 0; i<height; i++)// Sum of all the values
    {
          for(int j =0; j < width; j++) 
          {
              sum = sum + threshold[i][j];
          }
    }
}
    public boolean returnSum()
    {
        if(sum >= 300)
        {
            return true;
        }
        else
        return false;
    }

    public double returnVal()
    {
        return sum;
    }

}
6
  • Please do not post huge amounts of code. It is not appealing for people to wade through seas of code- instead, isolate the issue in a small snippet, and if you are still having trouble, then post here. Commented Apr 2, 2014 at 1:20
  • Thank you :) Hopefully you will get your answer then. Commented Apr 2, 2014 at 1:21
  • 1
    Most likely height = Active[0].length; should be height = Active.length; Commented Apr 2, 2014 at 1:57
  • 1
    It looks like there might be an error in how you are setting height in your Hjorth class. Try changing it to height = Active.length. Commented Apr 2, 2014 at 1:58
  • My understanding is that if I have int[5][3]. Active[0].length = 5 and Active[1].Length is 3? Right? Commented Apr 2, 2014 at 2:05

1 Answer 1

1

In recap, you needed to change height = Active[0].length; to height = Active.length;.

Think of a 2D array as an array of arrays. So Active is an array, and Active[0] is also an array. Active.length is how many arrays there are, and Active[0].length is how long each sub-array is. Hope that helps!

Sign up to request clarification or add additional context in comments.

Comments

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.