<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	
	>
<channel>
	<title>
	Comments on: An interesting uitree utility	</title>
	<atom:link href="https://undocumentedmatlab.com/articles/interesting-uitree-utility/feed" rel="self" type="application/rss+xml" />
	<link>https://undocumentedmatlab.com/articles/interesting-uitree-utility?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=interesting-uitree-utility</link>
	<description>Professional Matlab consulting, development and training</description>
	<lastBuildDate>Wed, 04 Oct 2017 08:17:39 +0000</lastBuildDate>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.7.3</generator>
	<item>
		<title>
		By: Yair Altman		</title>
		<link>https://undocumentedmatlab.com/articles/interesting-uitree-utility#comment-414419</link>

		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Wed, 04 Oct 2017 08:17:39 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=2218#comment-414419</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://undocumentedmatlab.com/articles/interesting-uitree-utility#comment-414405&quot;&gt;Peter Cook&lt;/a&gt;.

@Peter - Thanks for sharing]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://undocumentedmatlab.com/articles/interesting-uitree-utility#comment-414405">Peter Cook</a>.</p>
<p>@Peter &#8211; Thanks for sharing</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Peter Cook		</title>
		<link>https://undocumentedmatlab.com/articles/interesting-uitree-utility#comment-414405</link>

		<dc:creator><![CDATA[Peter Cook]]></dc:creator>
		<pubDate>Tue, 03 Oct 2017 23:09:52 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=2218#comment-414405</guid>

					<description><![CDATA[Yair,
I wrote this to fill a need I&#039;ve had for a lightweight &quot;structure explorer&quot; type utility that lets me navigate a struct quickly without the need to necessarily plot the data. I create the tree as I traverse the structure so I didn&#039;t have to make an ExpandFcn/MousePressedCallback; I also wrote a version that expands all nodes initially but it can be a bit overwhelming for a broad or deep tree (e.g. a struct returned by xml2struct). Maybe you or someone reading this page will find this useful as the original utility doesn&#039;t work in recent MATLAB releases.

&lt;pre lang=&quot;matlab&quot;&gt;
function mtree = mapStruct(s)

    hFig1 = figure(&#039;pos&#039;,[32,32,512,960]);
    hFig1.ToolBar = &#039;none&#039;;
    hFig1.MenuBar = &#039;none&#039;;
    hFig1.Name = &#039;Struct Explorer&#039;;
    hFig1.NumberTitle = &#039;off&#039;;

    root = uitreenode(&#039;v0&#039;,&#039;root&#039;,&#039;root&#039;,[],false);
    mtree = uitree(&#039;v0&#039;,&#039;Root&#039;,root,&#039;Parent&#039;,hFig1);

    function structTraverse(s,node)
        f = fieldnames(s);
        %explore each field in the input struct s
        for kField = 1 : length(f)
            structField = s.(f{kField}); %structField = getfield(s,f{kField});
            
            %if struct field is a cell array of structs, convert to struct array IFF structs are identical
            if iscell(structField)
                if all(cellfun(@isstruct,structField))
                    try
                        structField = [structField{:}];
                    catch
                        %add some sort of exception handling
                    end
                end
            end
            
            %if the structure field is also a struct explore each field
            if isstruct(structField) %strcmp(structFieldClass,&#039;struct&#039;)
                %determine depth of struct field &amp; enumerate if depth &gt; 1
                structDepth = length(structField);
                if structDepth &gt; 1
                    newNode = uitreenode(&#039;v0&#039;,f{kField},f{kField},[],false);
                    node.add(newNode);
                    %if the depth of the structure field is greater than 1
                    %add a blank parent node then add each layer/depth level as a node in the tree
                    for kLayer = 1:structDepth
                        nodeLayerName = sprintf(&#039;%s(%d)&#039;,f{kField},kLayer);
                        nextNode = uitreenode(&#039;v0&#039;, nodeLayerName,nodeLayerName,[],false);
                        newNode.add(nextNode);
                        structTraverse(structField(kLayer),nextNode)
                    end
                else
                    %if the depth of the structure field is 1 add it as a node
                    nextNode = uitreenode(&#039;v0&#039;,f{kField},f{kField},[],false);
                    node.add(nextNode);
                    structTraverse(structField,nextNode)
                end
            else
                %make a node for the variable/attribute and display information about the variable
                newNode = uitreenode(&#039;v0&#039;,f{kField},f{kField},[],false);
                [nRow,nCol] = size(structField);
                structFieldClass = class(structField);
                if isempty(structField)
                    displayString = &#039;empty&#039;;
                elseif nRow==1 &amp;&amp; ischar(structField)
                    displayString = structField;
                elseif nRow==1 &amp;&amp; nCol==1 &amp;&amp; any(strcmp(structFieldClass,{&#039;single&#039;,&#039;double&#039;,&#039;logical&#039;}))
                    displayString = sprintf(&#039;%f&#039;,structField);
                else
                    displayString = sprintf(&#039;%dx%d %s&#039;,nRow,nCol,structFieldClass);
                end
                nextNode = uitreenode(&#039;v0&#039;,displayString,displayString,[],true);
                newNode.add(nextNode);
                node.add(newNode);
            end
        end
    end
    
    structTraverse(s,root)
    mtree.reloadNode(root)
    mtree.Position(3) = 512;

end
&lt;/pre&gt;]]></description>
			<content:encoded><![CDATA[<p>Yair,<br />
I wrote this to fill a need I&#8217;ve had for a lightweight &#8220;structure explorer&#8221; type utility that lets me navigate a struct quickly without the need to necessarily plot the data. I create the tree as I traverse the structure so I didn&#8217;t have to make an ExpandFcn/MousePressedCallback; I also wrote a version that expands all nodes initially but it can be a bit overwhelming for a broad or deep tree (e.g. a struct returned by xml2struct). Maybe you or someone reading this page will find this useful as the original utility doesn&#8217;t work in recent MATLAB releases.</p>
<pre lang="matlab">
function mtree = mapStruct(s)

    hFig1 = figure('pos',[32,32,512,960]);
    hFig1.ToolBar = 'none';
    hFig1.MenuBar = 'none';
    hFig1.Name = 'Struct Explorer';
    hFig1.NumberTitle = 'off';

    root = uitreenode('v0','root','root',[],false);
    mtree = uitree('v0','Root',root,'Parent',hFig1);

    function structTraverse(s,node)
        f = fieldnames(s);
        %explore each field in the input struct s
        for kField = 1 : length(f)
            structField = s.(f{kField}); %structField = getfield(s,f{kField});
            
            %if struct field is a cell array of structs, convert to struct array IFF structs are identical
            if iscell(structField)
                if all(cellfun(@isstruct,structField))
                    try
                        structField = [structField{:}];
                    catch
                        %add some sort of exception handling
                    end
                end
            end
            
            %if the structure field is also a struct explore each field
            if isstruct(structField) %strcmp(structFieldClass,'struct')
                %determine depth of struct field &#038; enumerate if depth > 1
                structDepth = length(structField);
                if structDepth > 1
                    newNode = uitreenode('v0',f{kField},f{kField},[],false);
                    node.add(newNode);
                    %if the depth of the structure field is greater than 1
                    %add a blank parent node then add each layer/depth level as a node in the tree
                    for kLayer = 1:structDepth
                        nodeLayerName = sprintf('%s(%d)',f{kField},kLayer);
                        nextNode = uitreenode('v0', nodeLayerName,nodeLayerName,[],false);
                        newNode.add(nextNode);
                        structTraverse(structField(kLayer),nextNode)
                    end
                else
                    %if the depth of the structure field is 1 add it as a node
                    nextNode = uitreenode('v0',f{kField},f{kField},[],false);
                    node.add(nextNode);
                    structTraverse(structField,nextNode)
                end
            else
                %make a node for the variable/attribute and display information about the variable
                newNode = uitreenode('v0',f{kField},f{kField},[],false);
                [nRow,nCol] = size(structField);
                structFieldClass = class(structField);
                if isempty(structField)
                    displayString = 'empty';
                elseif nRow==1 &#038;& ischar(structField)
                    displayString = structField;
                elseif nRow==1 &#038;& nCol==1 &#038;& any(strcmp(structFieldClass,{'single','double','logical'}))
                    displayString = sprintf('%f',structField);
                else
                    displayString = sprintf('%dx%d %s',nRow,nCol,structFieldClass);
                end
                nextNode = uitreenode('v0',displayString,displayString,[],true);
                newNode.add(nextNode);
                node.add(newNode);
            end
        end
    end
    
    structTraverse(s,root)
    mtree.reloadNode(root)
    mtree.Position(3) = 512;

end
</pre>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Yair Altman		</title>
		<link>https://undocumentedmatlab.com/articles/interesting-uitree-utility#comment-349475</link>

		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Sun, 17 May 2015 08:56:43 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=2218#comment-349475</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://undocumentedmatlab.com/articles/interesting-uitree-utility#comment-349474&quot;&gt;Amir&lt;/a&gt;.

MathWorks removed the UserData property (and some other generic properties such as ApplicationData) from Java components a few releases ago. In general, code that relies on undocumented features cannot be expected to work forever, it may indeed break in some future release. 

You will need to contact the utility&#039;s creator to adapt it for new Matlab releases, or modify the relevant utility yourself, or hire a consultant to help you.]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://undocumentedmatlab.com/articles/interesting-uitree-utility#comment-349474">Amir</a>.</p>
<p>MathWorks removed the UserData property (and some other generic properties such as ApplicationData) from Java components a few releases ago. In general, code that relies on undocumented features cannot be expected to work forever, it may indeed break in some future release. </p>
<p>You will need to contact the utility&#8217;s creator to adapt it for new Matlab releases, or modify the relevant utility yourself, or hire a consultant to help you.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Amir		</title>
		<link>https://undocumentedmatlab.com/articles/interesting-uitree-utility#comment-349474</link>

		<dc:creator><![CDATA[Amir]]></dc:creator>
		<pubDate>Sun, 17 May 2015 08:48:55 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=2218#comment-349474</guid>

					<description><![CDATA[Hello Yair,

First your blog is really useful and helpful. 
I&#039;m working on a GUI that contain a uitree, now I wanted to export that uitree to enable user to save it to an external variable.
but, there is known problem that the java class is not serializable.
Now I&#039;m try to use that uitree utility in order to convert a struct to a uitree, but the utility is not working. (I&#039;m working with R2015a release)
It getting me an error message:
&quot;Error using set
The name &#039;UserData&#039; is not an accessible property for an instance of class
&#039;com.mathworks.mwswing.MJScrollPane&#039;.

Error in explorestruct (line 37)
set(tmp, &#039;UserData&#039;, cell_Data);&quot;


It looks like there is no &#039;UserData&#039; field for MJScrollPane, do you know why this field is unavailable and how to solve it?]]></description>
			<content:encoded><![CDATA[<p>Hello Yair,</p>
<p>First your blog is really useful and helpful.<br />
I&#8217;m working on a GUI that contain a uitree, now I wanted to export that uitree to enable user to save it to an external variable.<br />
but, there is known problem that the java class is not serializable.<br />
Now I&#8217;m try to use that uitree utility in order to convert a struct to a uitree, but the utility is not working. (I&#8217;m working with R2015a release)<br />
It getting me an error message:<br />
&#8220;Error using set<br />
The name &#8216;UserData&#8217; is not an accessible property for an instance of class<br />
&#8216;com.mathworks.mwswing.MJScrollPane&#8217;.</p>
<p>Error in explorestruct (line 37)<br />
set(tmp, &#8216;UserData&#8217;, cell_Data);&#8221;</p>
<p>It looks like there is no &#8216;UserData&#8217; field for MJScrollPane, do you know why this field is unavailable and how to solve it?</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Aurélien		</title>
		<link>https://undocumentedmatlab.com/articles/interesting-uitree-utility#comment-38755</link>

		<dc:creator><![CDATA[Aurélien]]></dc:creator>
		<pubDate>Mon, 04 Apr 2011 08:03:49 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=2218#comment-38755</guid>

					<description><![CDATA[I often use this utility in my GUIs that I call directly from uimenu . It allows me to check very quickly the contents of my structures. I also  added another cell in the right panel (like Name, Size , Class) to display the current value of selected item. Currently it is the best explorer of structure that I found on the FEX.

I am not really surprised that uitable , uitree are the most-popular search terms. IMHO, these features should have been officially implemented and documented in a MATLAB release for a while since they are really helpful.]]></description>
			<content:encoded><![CDATA[<p>I often use this utility in my GUIs that I call directly from uimenu . It allows me to check very quickly the contents of my structures. I also  added another cell in the right panel (like Name, Size , Class) to display the current value of selected item. Currently it is the best explorer of structure that I found on the FEX.</p>
<p>I am not really surprised that uitable , uitree are the most-popular search terms. IMHO, these features should have been officially implemented and documented in a MATLAB release for a while since they are really helpful.</p>
]]></content:encoded>
		
			</item>
	</channel>
</rss>
