kjo
kjo

Reputation: 35301

How to get more informative printouts from MATLAB?

Below is an example of the infuriatingly unhelpful printouts that MATLAB often produces:

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

How can I get MATLAB to produce something a bit more informative, such as

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

...or even just

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. I know that I can implement a MATLAB script to produce the output above. I'm looking for something much easier, analogous to Mathematica's TableForm@Map[MatrixForm, A, 2], for example. Also, I'm aware of the variable inspector, but I find it extremely cumbersome for examining items like the one shown in this thread.

Upvotes: 1

Views: 42

Answers (2)

Daniel
Daniel

Reputation: 36710

You could try the gencode.m from matlab file exchange. The output is:

>> 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

Upvotes: 1

Luis Mendo
Luis Mendo

Reputation: 112659

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

Try

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

Or

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

Upvotes: 4

Related Questions