Code covered by the BSD License  

Highlights from
SHOWCELL & CELL\DISP

3.6

3.6 | 5 ratings Rate this file 12 Downloads (last 30 days) File Size: 8.33 KB File ID: #9776
image thumbnail

SHOWCELL & CELL\DISP

by

 

27 Jan 2006 (Updated )

Displays cell array with long strings in the command window.

| Watch this File

File Information
Description

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.

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

See also DISP, DISPLAY

Acknowledgements

This file inspired Seis Lab 3.01.

MATLAB release MATLAB 6.5 (R13)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (13)
06 Nov 2013 Brian Wang  
04 Aug 2011 adam

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.
Thanks
Adam

07 Jul 2009 Chuanzhi  
31 Jan 2006 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.

30 Jan 2006 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.

30 Jan 2006 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???
us

30 Jan 2006 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.

28 Jan 2006 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. :)

28 Jan 2006 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.

28 Jan 2006 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)

28 Jan 2006 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
us

28 Jan 2006 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
ix=cellfun('isclass',arg,'char'),
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,
a={uint8(1),1000}
% [ 12]
% [1000]
however,
showcell(a)
erroneously yields
% [12]
% [255]

us

28 Jan 2006 Yevgen Gorshkov  
Updates
30 Jan 2006

Now allows more types of numeric class (DOUBLE, SINGLE, LOGICAL, UINT8, UINT16, UINT32, UINT64, INT8, INT16, INT32, INT64)

30 Jan 2006

Now allows more types of numeric class (DOUBLE, SINGLE, LOGICAL, UINT8, UINT16, UINT32, UINT64, INT8, INT16, INT32, INT64)

30 Jan 2006

Now allows more types of numeric class (DOUBLE, SINGLE, LOGICAL, UINT8, UINT16, UINT32, UINT64, INT8, INT16, INT32, INT64)

30 Jan 2006

Now allows more types of numeric class (DOUBLE, SINGLE, LOGICAL, UINT8, UINT16, UINT32, UINT64, INT8, INT16, INT32, INT64)

30 Jan 2006

Now allows more types of numeric class (DOUBLE, SINGLE, LOGICAL, UINT8, UINT16, UINT32, UINT64, INT8, INT16, INT32, INT64)

30 Jan 2006

Each column does not have to be of the same class. The cell elements can be of any class.

30 Jan 2006

Minor bug fixes. Fixed problems with displaying empty cell elements. Also supplying an overloaded DISPLAY method for cell arrays.

01 Feb 2006

Fixed displaying of an empty cell {}. Remove MORE function, since this can be achieved externally by calling MORE.

01 Feb 2006

Fixed displaying of an empty cell {}. Remove MORE function, since this can be achieved externally by calling MORE.

02 Nov 2010

License update

Contact us