5.0

5.0 | 3 ratings Rate this file 5 Downloads (last 30 days) File Size: 2.96 KB File ID: #36214
image thumbnail

struct2table

by Karl

 

16 Apr 2012

displays a struct's contents in a clear way...

| Watch this File

File Information
Description

Without losing too many words, this has been quite useful for me. Maybe you can also take advantage of this little tool... Anyway, here's a short description:

STRUCT2TABLE(S) displays a table with the field names in the headline
and one row for each struct element:

   # [field name 1] [field name 2] ...
   ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
   1 S(1).([field name 1]) S(1).([field name 2]) ...
   2 S(2).([field name 1]) S(2).([field name 2]) ...

   STRUCT2TABLE(S, F) displays only the fields with the names that are
   contained in the cell-array F.

      If the elements of F itself are also two-element cell arrays (e.g.
      F{1} = {'field1', 'round'}) individual display modes for each
      field's values can be set. Until now, two modes have been
      implemented, both only effective with numbers:

      'normal' - simply the value of the scalar
      'round' - the values are rounded before being displayed

      (also see "user parameters" below.)

   STRUCT2TABLE(H, S, F) displays a headline string H before creating the
   table.

   USER PARAMETERS Some aspects of the layout of the table can be set
   globally. In detail, the parameters are:

      N_decimal_digits - used to globally set the number of decimal digits
                    displayed
                    (applies only to numbers)
      str_disp_true - the string used to indicate locigal true
                    (applies only to logicals)
      str_disp_false - the string used to indicate logical false
                    (applies only to logicals)

Required Products MATLAB
MATLAB release MATLAB 7.9 (R2009b)
Tags for This File  
Everyone's Tags
command window, display, struct, table
Tags I've Applied
Add New Tags Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (4)
27 May 2013 Darik

Sorry... ignore that last comment. Works as expected. Very convenient

27 May 2013 Darik

Table is broken if structure contains a field name longer than 9 characters.

>> x(1:3) = struct('testfield', 1);
struct2table(x)
# |testfield
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
1 | 1
2 | 1
3 | 1

>> y(1:3) = struct('test_field', 1);
struct2table(y)
# |¯¯¯¯¯¯¯
1 | 2 | 3 |>>

26 May 2013 Darik  
14 Jun 2012 LP

nice!
Suggestion, if user passes a structure with fields of different length, perhaps use the 'median' length to define which fields to automatically display.

At the moment, it just displays field(1) and then exits..
looks good!

Contact us