File Exchange

image thumbnail


version (8.33 KB) by jiro
Displays cell array with long strings in the command window.

1 Download

Updated 01 Sep 2016

View Version History

View License

SHOWCELL Displays cell array with long strings in the command window.
CELL\DISP Overloaded DISP method for cell arrays.
CELL\DISPLAY Overloaded DISPLAY method for cell arrays.

SHOWCELL(A) displays the contents of a cell array A in the command window. It will format the display so that long strings will display appropriately.

Typically, if a cell array contains long strings, it will not display the text:

>> A

A =

[3] 'this is a text.' 'hello'
[4] 'More text' [ 32]
[6] [1x54 char] [ 53]

SHOWCELL will display it properly:

>> showcell(A)
[ 3] 'this is a text.' 'hello'
[ 4] 'More text' [32]
[ 6] 'This is a very long text that may not show up properly' [53]

Acceptable numbers are of class DOUBLE, SINGLE, LOGICAL, UINT8, UINT16, UINT32, UINT64, INT8, INT16, INT32, INT64. Elements other than CHAR or numbers are displayed as the size and name of the object,
e.g. [1x1 struct]

SHOWCELL(A,'option1',value1,...) specifies optional arguments passed in in pairs. Valid options are (abbreviated names accepted):

'spacing' - column spacing. Default is 4 spaces.
'numformat' - number of digits OR format string (see SPRINTF) for numerical values. Default is 5 digits.

showcell(A, 'spacing', 5);
showcell(A, 'numformat', 3);
showcell(A, 'n', '%0.4f');
showcell(A, 'sp', 2, 'nu', 6);


Cite As

jiro (2021). SHOWCELL & CELL\DISP (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (15)

Matthew Schroeder

Excellent! Thanks.

Renwen Lin

%The fellowing codesseems doesn‘t work:
cella={'henchanghengdccasda fas wentima','P0','Q0','P1','Q1','P2','Q2';'A',90,100,95,100,95,100000000;'B',50,200,45,200,45,200;'C',100,200,110,200,55,400};
showcell(cella, 'spacing', 7);

Brian Wang


Hi I really like the idea but it is not working for me. My cell array :
bestK =

[12x1 double] [ 6x1 char] [9.3654]
[20x1 double] [10x1 char] [9.1556]
[18x1 double] [ 9x1 char] [9.1175]
[16x1 double] [ 8x1 char] [8.8306]
[14x1 double] [ 7x1 char] [8.5591]
[22x1 double] [11x1 char] [7.7486]
[10x1 double] [ 5x1 char] [7.4001]
[24x1 double] [12x1 char] [7.2701]
[10x1 double] [ 5x1 char] [7.1714]
[18x1 double] [ 9x1 char] [6.9617]
The error message :

??? Error using ==> horzcat
CAT arguments dimensions are not consistent.

Error in ==> cell.strcat at 60
t{i} = [s{:,i}];

Error in ==> showcell>showcellEngine at 260
stringCell = strcat({''''}, cellArg(isNumChar(:, 1)), {''''}); %

Error in ==> showcell at 163
showcellEngine(this_arg, num_spaces, num_digits); %

If you can make it work it will be great.


Jiro Doke

Okay, the update was fixed (Thanks, Min!). Now, you should be able to download a zip file. I actually found another minor bug (yes, already), so I may update it once again.

Jiro Doke

I don't know what's wrong with the FEX site. I've tried to upload the new version, but each time it gives me an error. And apparently, the changes are not reflected by the actual file up here. So I've made a *new* submission (ZIP file) that includes the function and overloaded DISP, DISPLAY methods for cell array. Hopefully, it'll be up in a couple of days (even though the site gave me another error...). I think this version will be much more flexible addressing most of the issues in the reviews.

urs (us) schwarz

are you sure the latest upload is correct? the history talks about several changes - none of which i find in the latest m-file???

Jiro Doke

I have uploaded yet another version (will be up in a few days), which includes an overloaded DISPLAY method for cell arrays. It was developed using R13, and I've tried to test as thoroughly as possible. Please notify me of any bugs.

Jiro Doke

I have uploaded a new version, which should be up in a few days, that takes various numeric types. I've thought about overloading @cell/disp, but this requires more thinking on my part to deal with various object types and non-coherent types among columns. Maybe someone else can do this. :)

John D'Errico

Nice idea. The behavior of disp on cell arrays has always frustrated me. A thought is to overload disp for cell arrays, using the showcell code instead. You could implement the overloaded @cell/disp in this submission along with showcell to give the user their choice.

Jiro Doke

Points well taken, us. Good point about doing the error checking more up front. About UINT8, I obviously did not consider all possible cases (as I never stumbled upon such situations). I can put some restrictions on it, or do some more elaborate coversions, but I guess that will make things very convoluted.

I guess this code is too specific, and may not be useful in a general sense. I may take this off soon, and upload a new one once I decide to create a more general code (possibly incorporating R14SP3 features)

urs (us) schwarz

there are two stupid and misleading errors in the review below due to the petty size of the web-window, which often makes it hard to keep track of things...
- NOW -> NOT
- a={uint8(1),1000} -> a={uint8(12);1000}
sorry for confusion

urs (us) schwarz

nice helper
since the code was meant to run with r13, one has to accept the somewhat elaborate engine and severe restrictions (same data type per col and numbers/chars only), which would be a few lines and more versatile with r14.sp3 due to the great new functionality of CELLFUN...

however, there are problems that need to be addressed
- while the author clearly states ...Each column must only contain data of the same type... the algorithm does NOW work with inputs of the form
a={1,'foo'}, ie, NUMERIC;CHAR,
which crash badly. they are NOT caught in line#154 since they pass line#138 and get killed in line#142 (due to the - now unchecked - {:,id} syntax).
in this readers view, the authors should check the validity of the input at the very beginning with a construct like
which is available in r13, and error-out early on
- there's an issue with cell class promotion/demotion that is not mentioned and/or taken care of, eg,
% [ 12]
% [1000]
erroneously yields
% [12]
% [255]


Yevgen Gorshkov

MATLAB Release Compatibility
Created with R13
Compatible with any release
Platform Compatibility
Windows macOS Linux

Inspired: SeisLab 3.01

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!