Display matrix with row and column labels

前端 未结 6 1835
误落风尘
误落风尘 2020-12-01 14:08

Is there a convenient way to display a matrix with row and column labels in the Matlab terminal? Something like this:

M = rand(5);
displaymatrix(M, {\'FOO\'         


        
6条回答
  •  旧时难觅i
    2020-12-01 14:54

    I know this is an old post, but I believe the solution is to use array2table. Specifically in the case of the OP, one would simply do:

    >> M = rand(5);
    >> names= {'A','B','C','D','E'}; 
    >> array2table( M, 'VariableNames', names, 'RowNames', names )
    
    ans = 
    
                A          B          C          D          E    
             _______    _______    _______    _______    ________
    
        A    0.81472    0.09754    0.15761    0.14189     0.65574
        B    0.90579     0.2785    0.97059    0.42176    0.035712
        C    0.12699    0.54688    0.95717    0.91574     0.84913
        D    0.91338    0.95751    0.48538    0.79221     0.93399
        E    0.63236    0.96489    0.80028    0.95949     0.67874
    

提交回复
热议问题