octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: displaying structures array as table


From: John W. Eaton
Subject: Re: displaying structures array as table
Date: Tue, 30 Aug 2011 14:41:03 -0400

On 30-Aug-2011, fork wrote:

| CdeMills <Pascal.Dupuis <at> worldonline.be> writes:
| 
| >  What I would
| > like is to concatenate a number of numeric values together in a matrix-like
| > fashion, but be able to give some signification for each line: the name of
| > the first should be 'fmin', the name of the second 'fnext', and so on. Added
| > benefit is that 'a(2).fmin' doesn't need to be rewritten when fields are
| > added/deleted, while a(2, 1) would change if I decide to insert a line
| > before the first one.
| > 
| > For my request to work, this implies all fields to be similar. Any interest
| > in this idea ?
| 
| (Forgive me if the following is non-germane.)
| 
| What about a function to display heterogeneous data stored in a struct-array? 
| The code could use the first few rows of the struct array to infer types and
| lengths, build a format string therefrom, and then loop over the rest.  Using
| the first few rows seems sort of "cheesy", but is necessary unless one keeps
| some sort of metadata saying what the types are (which would probably be a 
thing
| for objects and classes).  One could fairly easily write the inverse function
| that parses a text table in the same format and stores a struct array (good 
for
| testing, too).
| 
| (Maybe you want something more than display? Honestly displaying heterogeneous
| data is the only reason I miss R.)
| 
| Then you could have something like the following:
| 
| a(1).label = 'first';  a(1).x = 1; a(1).y=10;
| a(2).label = 'second'; a(2).x = 2; a(2).y=25;
| 
| > dispt(a)
| 
| label   x  y
| ------------
| first   1 10
| second  2 25

I don't object to improving the default display functions, but no
matter what we do we are unlikely to please everyone all the time.  So
maybe it would be best if we allowed users to customize the output by
defining a function?

jwe


reply via email to

[Prev in Thread] Current Thread [Next in Thread]