如何从MATLAB获得更多信息丰富的打印输出?

时间:2014-03-21 21:23:41

标签: matlab

下面是MATLAB经常产生的无用打印输出的例子:

>> A
A = 
    {2x1 cell}    {3x3 cell}    {2x1 cell}
    {3x1 cell}    {3x3 cell}    {3x1 cell}

如何让MATLAB生成更具信息性的内容,例如

A =
    17    24  1  8    15
    23     5  7 14    16

     4     6 13 20    22
    10    12 19 21     3
    11    18 25  2     9

......甚至只是

A =
    {{17; 23} {24 1 8; 5 7 14} {15; 16}; {4; 10; 11} {6 13 20; 12 19 21; 18 25 2} {22; 3; 9}}


P.S。我知道我可以实现一个MATLAB 脚本来产生上面的输出。我正在寻找更容易的东西,例如类似于 Mathematica TableForm@Map[MatrixForm, A, 2]。另外,我了解变量检查器,但我发现检查此线程中显示的项目非常麻烦。

2 个答案:

答案 0 :(得分:4)

>> A = {{2;1}, {3;1}}

尝试

>> A{:}
ans = 
    [2]
    [1]
ans = 
    [3]
    [1]

或者

>> celldisp(A)
A{1}{1} =
     2
A{1}{2} =
     1
A{2}{1} =
     3
A{2}{2} =
     1

答案 1 :(得分:1)

您可以尝试matlab文件交换中的gencode.m。输出是:

>> char(gencode(A))

A{1, 1} = {        
           17      
           23      
           };      
A{1, 2}{1, 1} = 24;
A{1, 2}{1, 2} = 1; 
A{1, 2}{1, 3} = 8; 
A{1, 2}{2, 1} = 5; 
A{1, 2}{2, 2} = 7; 
A{1, 2}{2, 3} = 14;
A{1, 2}{3, 1} = 6; 
A{1, 2}{3, 2} = 13;
A{1, 2}{3, 3} = 20;
A{1, 3} = {        
           15      
           16      
           };      
A{2, 1} = {        
           4       
           10      
           11      
           };      
A{2, 2}{1, 1} = 6; 
A{2, 2}{1, 2} = 13;
A{2, 2}{1, 3} = 20;
A{2, 2}{2, 1} = 12;
A{2, 2}{2, 2} = 19;
A{2, 2}{2, 3} = 21;
A{2, 2}{3, 1} = 18;
A{2, 2}{3, 2} = 25;
A{2, 2}{3, 3} = 2; 
A{2, 3} = {        
           22      
           3       
           9       
           };      

http://www.mathworks.com/matlabcentral/fileexchange/24447-generate-m-file-code-for-any-matlab-variable/content/gencode.m