简体   繁体   English

使用IntelliJ IDEA调试Java时如何可视化整个矩阵?

[英]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. 我正在使用IntelliJ IDEA来调试Java中的程序,该程序大量使用double [] []矩阵。 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. 我已经搜索了很多方法,但是当使用PyCharm在Python中执行类似的操作似乎很简单时,使用Java / IntelliJ IDEA似乎并不容易。 I've also tried to customize the Java type renderer, but with no success. 我也尝试过自定义Java类型渲染器,但是没有成功。 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. 该方案将无需任何额外的努力即可应用于程序中的所有2D阵列。 I hope this will help. 我希望这将有所帮助。

For now I've found an useful workaround by using ejml library's DMatrixRMaj type. 现在我已经用ejml图书馆发现了一个有用的解决方法DMatrixRMaj类型。

I simply use this personalized Java Type Renderer (section accessible by right-clicking on variable/Customize Data Views/Java Type Renderers ) 我只是使用了这种个性化的Java Type Renderer(可通过右键单击变量/ Customize Data Views / Java Type Renderers来访问该部分)

在此处输入图片说明

Then I right click on the matrix and select view text . 然后,右键单击矩阵并选择查看文本 There is a straightforward version for arrays. 数组有一个简单的版本。

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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