Display matrix with row and column labels

前端 未结 6 1833
误落风尘
误落风尘 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条回答
  •  鱼传尺愫
    2020-12-01 14:58

    It looks like your data has some structure to it so you can put it in a more structured class - a dataset, part of the Statistics toolbox.

    >> M = rand(5);
    >> dataset({M 'FOO','BAR','BAZ','BUZZ','FUZZ'}, ...
                    'obsnames', {'ROW1','ROW2','ROW3','ROW4','ROW5'})
    
    ans = 
                FOO        BAR         BAZ        BUZZ         FUZZ    
        ROW1    0.52853     0.68921    0.91334     0.078176     0.77491
        ROW2    0.16565     0.74815    0.15238      0.44268      0.8173
        ROW3    0.60198     0.45054    0.82582      0.10665     0.86869
        ROW4    0.26297    0.083821    0.53834       0.9619    0.084436
        ROW5    0.65408     0.22898    0.99613    0.0046342     0.39978
    

    Alternatively, if you are publishing your output, here is one example of several functions that will take a matrix w/ row,col names and produce an html formatted table.

提交回复
热议问题