Search Comments and Ratings

go

Comments and Ratings

   
Date File Comment by Comment Rating
15 Mar 2009 Map fields of a structure to output variables The program assigns each field of a structure into output arguments. Author: Hoi Wong Wong, Hoi

Thanks jos for the alternative approach that use deal(). The reason that I made this wrapper is to avoid using deal() and make the code self-documenting.

I wish Mathworks can consider allowing syntaxes like [a,b,c]=(struct2cell(S)){:}, then my submission has no reason to be here. :)

12 Mar 2009 Map fields of a structure to output variables The program assigns each field of a structure into output arguments. Author: Hoi Wong Jos

A superfluous combination of two basic ML commands. Simply using
C = struct2cell(S) ; [a,b,c] = deal(C{:}) ; in your code is clear enough.

07 Jan 2009 Nested Structure to Flat Cell Vector Tools to flatten a nested struct into cell Author: Hoi Wong Shilon, Ofek

Exactly what i needed, works like charm. thanks!

21 Apr 2008 Nested Structure to Flat Cell Vector Tools to flatten a nested struct into cell Author: Hoi Wong lee, e

I found this very handy, I wanted to do a simple check if a nested structure field existed or not, but it seems overly difficult to do this (exist doesn't work for nested structure fiels, isvar works for one level of nesting, etc.)
I was able to do a strcmp on the output to find if the nested structure field exists.

I would also really like to have a gui (like what is shown) that lets you see and edit the values of the structure easily. I would love to have a "tree grid" where nodes could be collapsed (similar to what you show on the right part of the screen shot, with an additional column for the values. But, maybe I am dreaming.

For handling "non-singleton struct branch" perhaps you can find some hints in the Geodise "xml toolbox", it seems to be able to parse pretty complicated matlab structures into xml.

Regards,
Eric

19 Feb 2008 Nested Structure to Flat Cell Vector Tools to flatten a nested struct into cell Author: Hoi Wong Wong, Hoi

Thanks Duane for the useful comments. I actually thought of spending more time on the help file, but I just find it quite difficult to describe what the program does without an example screenshot that has the structure displayed as a tree. I'll post a screen shot in a day or two, and I'd appreciate any help describing what this program does in simple words.

struct2cell() works for one level structures only. Hence if you have a structed formed by

a.b.c.d = 1
a.p.q.r = 2

struct2cell() will still give you cells that contains structs, which is not what I wanted (basically I want to form a table from a nested struct).

Also, in this context, since I want a list of all possible leaf nodes in a nested struct, using anything other than feval will make the program extremely clumsy. Please let me know if anybody has a better idea :)

I intentionally separate flatStructAccessList() from flatStruct() because some people might just want a list (like tree view) without the computational work putting all the contents into a cell vector.

By the way, "No vector (or cell vector)" should be written as "No non-singleton struct branch allowed". For structs, it's possible to have something like:

a{1}.b=1
a{2}.c=3
p(1).q=2
p(2).q=4

In this case, 'a' is a vector of cells which all the elements are structs, and 'p' is a vector which all the elements are structs. I don't know how to describe them in simple words, so please help!

If you found a good way to describe it, send me a email at wonghoi.ee@gmail.com.

19 Feb 2008 Nested Structure to Flat Cell Vector Tools to flatten a nested struct into cell Author: Hoi Wong Hanselman, Duane

This might be useful, but being a 23+ year MATLAB user, I can't figure out what it does from the help text. I am especially troubled by the appearance of the function eval being called within a for loop. Would it make sense to make flatStructAccessList to be a subfunction of flattenStruct? Does this do what the builtin function struct2cell already does? What is meant by saying "No vector (or cell vector) allowed anywhere in the input struct!"?

 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com