简体   繁体   中英

How to visualize an entire matrix when debugging Java with IntelliJ IDEA?

I'm using IntelliJ IDEA for debugging a program in Java, that has an intense use of double[][] matrixes. I would like to find a method for easily displaying these matrixes during debugging, not just like:

在此处输入图片说明

But more like an entire matrix, for example something like this

在此处输入图片说明

A visualization like this should be displayed in the debugger variable's window.

I've searched many ways, but when it seems straightforward to do something like this in Python with PyCharm, it doesn't seem easy with Java/IntelliJ IDEA. I've also tried to customize the Java type renderer, but with no success. How can I do this?

Please add this method in any of your class:

public static String get2DArrayPrint(int[][] matrix) {
    String output = new String();
    for (int i = 0; i < matrix.length; i++) {
        for (int j = 0; j < matrix[i].length; j++) {
            output = output + (matrix[i][j] + "\t");
        }
        output = output + "\n";
    }
    return output;
}

Now in debugger mode right click in your variable and select view as -> Create Option. It will open screen similar to this:

在此处输入图片说明

Now in debugger mode right click on your variable and select view as -> Your scheme name (please check the screenshot).

在此处输入图片说明

Once it's done, please right click on a variable in debugger mode and select 'View Text'. This scheme will be applied to all 2D arrays in the program without any additional efforts. I hope this will help.

For now I've found an useful workaround by using ejml library's DMatrixRMaj type.

I simply use this personalized Java Type Renderer (section accessible by right-clicking on variable/Customize Data Views/Java Type Renderers )

在此处输入图片说明

Then I right click on the matrix and select view text . There is a straightforward version for arrays.

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM