[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: displaying structures array as table
From: |
Ben Abbott |
Subject: |
Re: displaying structures array as table |
Date: |
Thu, 01 Sep 2011 17:22:37 -0400 |
On Sep 1, 2011, at 4:45 AM, CdeMills wrote:
> forkandwait wrote:
>>
>>
>> (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
>>
>
> Enclosed in a first try at implementing this.
> Prerequise:
> -a structure array with a vector shape
> -all fields are numeric
> This function is a wrapper around 'disp', so global formating preferences
> are used. Field names are used as row/column headers, according to the
> structure orientation. Empty values are printed as 'NA', and when the
> elements do not all have the same length, the shorter ones are padded with
> blanks. Comment, remarks, and ameliorations are welcome.
>
> Regards
>
> Pascal
I applied jwe's patch, created a directory in my pwd() named @struct and placed
the function below in it. I have tabdisp.m in my pwd.
function display (a)
if (size (a, 1) == 1 && all (cellfun (@isnumeric, struct2cell(a)(:))))
tabdisp (a)
else
disp (a)
endif
end
Now I see ...
>> a=[]; a(1).a = 1; a(2).a=2; a(1).b = 3; a(2).b = 4;
>> a
ans =
a 1 2
b 3 4
Ben