2
votes

So I'm trying to do a project for a class modeling random walks and applications. I'm doing most of the programming in Java Eclipse, but I'd like to make the plots in Mathematica. I'm creating arrays in Eclipse with for loops. Then I write the array into a txt file via

    try {
        PrintWriter outputStream = new PrintWriter(fileName1);
        for(int j = 0; j<M; j++) {
            outputStream.println(deltaX[j]);
        }
        outputStream.close(); //can't write to this anymore, but flushes data do file
        System.out.println("Done");

    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

and then read it into Mathematica using

randWalkDist = Import["randomWalkDistribution.txt", "Data"];

but I seem to be getting a list of 1D lists instead of just a list of numbers. Mathematica will tell me the standard deviation and the mean of the numbers, but can't come up with a mode and can't make a histogram, which is what I'd really like.
Any suggestions?

1

1 Answers

0
votes

This is because you create a file that has one number in each line. If you would make just a space between the numbers, you would get a normal list. Anyway, without changing your Java code you can simply use

randWalkDist = Flatten[Import["randomWalkDistribution.txt", "Data"]];

to flatten out the inner lists. After this everything should work.