如何在 Matlab 中格式化自定义 class 的命令 window 输出?

How can I format the command window output of a custom class in Matlab?

当我调用对象ob自定义class时,如何在Matlab中的command-window中实现格式化输出?自定义 class 的常规输出是所有 public 属性的列表,如下所示。

customss with properties:

    A: [8×8 double]
    B: [8×1 double]
    C: [2×8 double]
    D: [2×1 double]

例如,当我在 Matlab 中创建状态 space 模型,然后在命令 window 中调用对象时,输出是系统矩阵和采样时间的格式化表示。即使通过调试我也无法弄清楚是否可能调用某个函数来实现这一点。那么,如何创建这样的自定义输出?

MATLAB 有一个特殊的抽象 class matlab.mixin.CustomDisplay,您的 class 可以继承它来自定义显示行为。

MathWorks 有一个 detailed documentation section 涵盖了允许的各种自定义。