【问题标题】:How to set a title with the contents of a matrix?如何使用矩阵的内容设置标题?
【发布时间】:2019-06-16 22:17:37
【问题描述】:

想法 我试图在 matlab 中设置一个图形的名称,该名称显示一个名为 NM 的迭代矩阵的内容,长度为 MxN。

问题 它根本不显示矩阵,或者所有内容仅显示在垂直列中

代码

title({[ NM(1,:)];[NM(2,:)]})

【问题讨论】:

    标签: matlab matlab-figure matlab-guide


    【解决方案1】:

    使用mat2str将矩阵转换为字符串(字符数组),然后替换字符[、]和;如下:

    title(replace(mat2str(NM), {';', '[', ']'}, {'\newline', '', ''}))
    

    由于格式可能非常难看,您可能需要考虑使用uitable:

    MN = magic(5);
    
    f = figure();
    % first axis to plot data
    ax(1) = subplot(211);
    imagesc(MN)
    
    % second axis to take position from
    ax(2) = subplot(212); ax(2).Visible = 'off';
    uitable(f, 'Data', MN, 'Units', 'normalized', 'Position', ax(2).Position)
    

    【讨论】:

    • 以及如何对齐 uitable?,因为它与图形重叠,我更喜欢这个解决方案而不是标题。
    • 查看我的编辑,想法是使用subplot 来处理定位,然后将uitable 放在子图上。如果你愿意,你甚至可以从图中删除子图。
    猜你喜欢
    • 1970-01-01
    • 2019-05-26
    • 2018-09-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多