<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>schema.class &#8211; Undocumented Matlab</title>
	<atom:link href="https://undocumentedmatlab.com/articles/tag/schemaclass/feed" rel="self" type="application/rss+xml" />
	<link>https://undocumentedmatlab.com</link>
	<description>Professional Matlab consulting, development and training</description>
	<lastBuildDate>Wed, 23 Oct 2013 22:01:32 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.7.2</generator>
	<item>
		<title>Draggable plot data-tips</title>
		<link>https://undocumentedmatlab.com/articles/draggable-plot-data-tips?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=draggable-plot-data-tips</link>
					<comments>https://undocumentedmatlab.com/articles/draggable-plot-data-tips#comments</comments>
		
		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Wed, 23 Oct 2013 22:01:32 +0000</pubDate>
				<category><![CDATA[Handle graphics]]></category>
		<category><![CDATA[Hidden property]]></category>
		<category><![CDATA[High risk of breaking in future versions]]></category>
		<category><![CDATA[Stock Matlab function]]></category>
		<category><![CDATA[Undocumented feature]]></category>
		<category><![CDATA[HG2]]></category>
		<category><![CDATA[Pure Matlab]]></category>
		<category><![CDATA[schema.class]]></category>
		<category><![CDATA[schema.prop]]></category>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=4294</guid>

					<description><![CDATA[<p>Matlab's standard plot data-tips can be customized to enable dragging, without being limitted to be adjacent to their data-point. </p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/draggable-plot-data-tips">Draggable plot data-tips</a> appeared first on <a rel="nofollow" href="https://undocumentedmatlab.com">Undocumented Matlab</a>.</p>
<div class='yarpp-related-rss'>
<h3>Related posts:</h3><ol>
<li><a href="https://undocumentedmatlab.com/articles/controlling-plot-data-tips" rel="bookmark" title="Controlling plot data-tips">Controlling plot data-tips </a> <small>Data-tips are an extremely useful plotting tool that can easily be controlled programmatically....</small></li>
<li><a href="https://undocumentedmatlab.com/articles/accessing-plot-brushed-data" rel="bookmark" title="Accessing plot brushed data">Accessing plot brushed data </a> <small>Plot data brushing can be accessed programmatically using very simple pure-Matlab code...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/undocumented-scatter-plot-jitter" rel="bookmark" title="Undocumented scatter plot jitter">Undocumented scatter plot jitter </a> <small>Matlab's scatter plot can automatically jitter data to enable better visualization of distribution density. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/plot-liminclude-properties" rel="bookmark" title="Plot LimInclude properties">Plot LimInclude properties </a> <small>The plot objects' XLimInclude, YLimInclude, ZLimInclude, ALimInclude and CLimInclude properties are an important feature, that has both functional and performance implications....</small></li>
</ol>
</div>
]]></description>
										<content:encoded><![CDATA[<p>A couple of years ago, I was asked by a client to figure out a way to make Matlab plot data-tips movable. The problem was that he had a very crowded plot and Matlab&#8217;s standard data-tips are displayed immediately adjacent to the data, thereby overlapping the plot parts. Matlab&#8217;s standard data-tips enable dragging to a very limited extent (only to the 4 corners of the data-point), and in any case the displayed textbox remains directly attached to the data point.<br />
So I developed a small utility for my client that solves this problem. I then forgot all about it until a few days ago when I came across it again. Yesterday I uploaded this <i><b>draggableDataTips</b></i> utility to the File Exchange, where you can <a target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/44065-draggable-data-tips">download it</a>.<br />
<i><b>draggableDataTips</b></i> enables the user to interactively drag any newly-created data-tip, anywhere in the Matlab figure. A dashed line connects the dragged data-tip with the original data point. Simple, intuitive, and effective. At 300 lines, the <i>draggableDataTips.m</i> source code is compact and easy to follow, and you&#8217;re welcome to take a look and further customize this utility for your specific needs.<br />
<center><figure style="width: 451px" class="wp-caption aligncenter"><a target="_blank" href="/images/draggableDataTips.png"><img fetchpriority="high" decoding="async" alt="draggableDataTips utility in action" src="https://undocumentedmatlab.com/images/draggableDataTips.png" title="draggableDataTips utility in action" width="451" height="293" /></a><figcaption class="wp-caption-text"><i><b>draggableDataTips</b></i> utility in action</figcaption></figure></center><br />
<span id="more-4294"></span></p>
<h3 id="implementation">Technical implementation</h3>
<p>The implementation of <i><b>draggableDataTips</b></i> relies on undocumented aspects of the data-cursor object exposed via the <i><b>datacursormode</b></i> function. I have already shown how these can be used to <a target="_blank" href="/articles/controlling-plot-data-tips/">customize and control data-tips programmatically</a> (rather than interactively). For <i><b>draggableDataTips</b></i>, we first get the cursor object&#8217;s meta-data <i><b>classhandle</b></i> (a <i><b>schema.class</b></i> object), then use it to find the meta-data for its hidden <b>CurrentDataCursor</b> property (a <i><b>schema.prop</b></i> object). There is also a more direct approach, using the <i><b>findprop</b></i> function.<br />
Whichever alternative we choose, we finally use this object to set the property&#8217;s <b>SetFunction</b> meta-property. Quite straight-forward, I should say:</p>
<pre lang='matlab'>
% Get the cursor-mode object
cursorObj = datacursormode(hFig);
% Alternative #1: the indirect route to the meta-property
ch = classhandle(cursorObj);
hPropIdx = strcmpi(get(ch.Properties,'Name'), 'CurrentDataCursor');
hProp = ch.Properties(hPropIdx);
% Alternative #2: the direct approach
hProp = findprop(cursorObj, 'CurrentDataCursor');
% Update the meta-property to use a custom function whenever new data-tips are created
hProp.SetFunction = @installNewMoveFcn;
</pre>
<p>This has the effect that all new data-tips that will be created from then on will call our custom <i>installNewMoveFcn</i> function when the data-tip object is created. This <i>installNewMoveFcn</i> function, in turn, simply replaces the data-tips standard default callback for mouse movement (which is used while dragging), to a new custom function <i>textBoxUpdateFcn</i>:</p>
<pre lang='matlab'>
% Install a replacement callback function for datatip textbox mouse movement
function hDataTip = installNewMoveFcn(cursorObj, hDataTip)
    srcObjs = get(hDataTip.SelfListenerHandles,'SourceObject');
    for srcIdx = 1 : length(srcObjs)
        if strcmpi(srcObjs{srcIdx}.Name,'Orientation')
            hDataTip.SelfListenerHandles(srcIdx).Callback = @textBoxUpdateFcn;
            hDataTip.MarkerHandle.Marker = 'none';
            break;
        end
    end
end
</pre>
<p>The <i>textBoxUpdateFcn</i> function basically moves the datatip textbox to the new mouse location, without limiting its positions as Matlab&#8217;s standard default callback function did. A dashed connector line is then drawn to connect the center of the textbox with the data-point. It&#8217;s a bit long to include here, but interested readers are welcome to look at the code (lines #99 onward in <i>draggableDataTips.m</i>).<br />
As can be seen from the screenshot above, standard and draggable data-tips can be used in the same plot. This is done by simply turning the draggability functionality on and off by <i><b>draggableDataTips</b></i> before creating a new data-tip (using either alt-click or <a target="_blank" href="/articles/controlling-plot-data-tips/">programmatically</a>):</p>
<pre lang='matlab'>
draggableDataTips on    % or: draggableDataTips('on')  or: draggableDataTips(true)
draggableDataTips off   % or: draggableDataTips('off') or: draggableDataTips(false)
</pre>
<p>Notes:</p>
<ol>
<li>The actual code of <i><b>draggableDataTips</b></i> naturally contains more sanity checks, exception handling etc. I have only presented the core code in the snippets above, but you should always include such extra checks in any real-life program.</li>
<li>There is a minor bug that causes the connector line to be on top of the box rather than beneath it, but aside from this all works ok. For some reason, <i><b>uistack</b></i> did not work. If anyone has a fix for this bug, please let me know.</li>
<li>Did you notice that Java was not mentioned anywhere above? Mode managers, such as the data-cursor mode, use pure-Matlab functionality.</li>
</ol>
<h3 id="HG2">HG2</h3>
<p>Unfortunately, when I tested <i><b>draggableDataTips</b></i> on <a target="_blank" href="/articles/hg2-update/">HG2</a>, Matlab&#8217;s upcoming new graphics engine, the utility failed. Data-cursors have undergone a significant reengineering in HG2 (about time!), causing multiple properties and methods to change names and functionality. But this could be overcome (see lines #43-53 in <i>draggableDataTips.m</i>).<br />
However, I could not overcome the apparent fact that unlike HG1 (or more specifically, <i><b>schema</b></i> objects, that HG1 uses for its data-tips functionality), in HG2 (or rather, MCOS class objects) we cannot override an object&#8217;s meta-properties, specifically its <b>SetMethod</b> (which is the MCOS equivalent of <i><b>schema.prop</b></i>&#8216;s <b>SetFunction</b> meta-property).<br />
So for the moment, <i><b>draggableDataTips</b></i> does not work on HG2. I hope to find a solution for this by the time HG2 launches. If anyone finds a fix for the problem, please let me know. If I ever find or receive a fix, I will update this post with the relevant technical details.<br />
For the moment there is no rush, since HG2 is still relatively far away in the distant future, and <i><b>draggableDataTips</b></i> works splendidly in the current HG1.<br />
Have you used plot data-tips in some nifty way? If so, please share your experience in a comment below.</p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/draggable-plot-data-tips">Draggable plot data-tips</a> appeared first on <a rel="nofollow" href="https://undocumentedmatlab.com">Undocumented Matlab</a>.</p>
<div class='yarpp-related-rss'>
<h3>Related posts:</h3><ol>
<li><a href="https://undocumentedmatlab.com/articles/controlling-plot-data-tips" rel="bookmark" title="Controlling plot data-tips">Controlling plot data-tips </a> <small>Data-tips are an extremely useful plotting tool that can easily be controlled programmatically....</small></li>
<li><a href="https://undocumentedmatlab.com/articles/accessing-plot-brushed-data" rel="bookmark" title="Accessing plot brushed data">Accessing plot brushed data </a> <small>Plot data brushing can be accessed programmatically using very simple pure-Matlab code...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/undocumented-scatter-plot-jitter" rel="bookmark" title="Undocumented scatter plot jitter">Undocumented scatter plot jitter </a> <small>Matlab's scatter plot can automatically jitter data to enable better visualization of distribution density. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/plot-liminclude-properties" rel="bookmark" title="Plot LimInclude properties">Plot LimInclude properties </a> <small>The plot objects' XLimInclude, YLimInclude, ZLimInclude, ALimInclude and CLimInclude properties are an important feature, that has both functional and performance implications....</small></li>
</ol>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://undocumentedmatlab.com/articles/draggable-plot-data-tips/feed</wfw:commentRss>
			<slash:comments>6</slash:comments>
		
		
			</item>
		<item>
		<title>Extending a Java class with UDD</title>
		<link>https://undocumentedmatlab.com/articles/extending-a-java-class-with-udd?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=extending-a-java-class-with-udd</link>
					<comments>https://undocumentedmatlab.com/articles/extending-a-java-class-with-udd#comments</comments>
		
		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Thu, 29 Mar 2012 14:32:46 +0000</pubDate>
				<category><![CDATA[Guest bloggers]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Medium risk of breaking in future versions]]></category>
		<category><![CDATA[Undocumented feature]]></category>
		<category><![CDATA[Donn Shull]]></category>
		<category><![CDATA[schema]]></category>
		<category><![CDATA[schema.class]]></category>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=2824</guid>

					<description><![CDATA[<p>Java classes can easily be extended in Matlab, using pure Matlab code. </p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/extending-a-java-class-with-udd">Extending a Java class with UDD</a> appeared first on <a rel="nofollow" href="https://undocumentedmatlab.com">Undocumented Matlab</a>.</p>
<div class='yarpp-related-rss'>
<h3>Related posts:</h3><ol>
<li><a href="https://undocumentedmatlab.com/articles/java-class-access-pitfalls" rel="bookmark" title="Java class access pitfalls">Java class access pitfalls </a> <small>There are several potential pitfalls when accessing Matlab classes from Matlab. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/accessing-internal-java-class-members" rel="bookmark" title="Accessing internal Java class members">Accessing internal Java class members </a> <small>Java inner classes and enumerations can be used in Matlab with a bit of tweaking. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/udd-and-java" rel="bookmark" title="UDD and Java">UDD and Java </a> <small>UDD provides built-in convenience methods to facilitate the integration of Matlab UDD objects with Java code - this article explains how...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/creating-a-simple-udd-class" rel="bookmark" title="Creating a simple UDD class">Creating a simple UDD class </a> <small>This article explains how to create and test custom UDD packages, classes and objects...</small></li>
</ol>
</div>
]]></description>
										<content:encoded><![CDATA[<p><i>Once again I welcome Donn Shull, with another article about Matlab&#8217;s internal UDD mechanism</i></p>
<h3 id="Introduction">Extending a Java class with UDD</h3>
<p>During the <a target="_blank" href="/?s=UDD">series on UDD</a>, we have mentioned the connection between UDD and Java. In <a target="_blank" href="/articles/udd-events-and-listeners/">UDD Events and Listeners</a> we described how in Matlab, each Java object can have a UDD companion. In <a target="_blank" href="/articles/hierarchical-systems-with-udd/">Hierarchical Systems with UDD</a> we briefly noted that a UDD hierarchy may be passed to Java. In the numerous posts on handle graphics and callbacks, Yair has discussed the UDD packages <code>javahandle</code> and <code>javahandle_withcallbacks</code>. Based on this information, it seems reasonable to speculate that it may be possible to extend a Java class with UDD using UDD&#8217;s class inheritance mechanism.<br />
This can be extremely useful in two cases:</p>
<ul>
<li>You don&#8217;t know Java but found a Java class you would like to use in Matlab, it just needs minor modifications for your specific needs</li>
<li>You do know Java, but don&#8217;t have access to the original source code, and choose to extend the Java class with Matlab code, rather than Java code</li>
</ul>
<p>Today I will show how this can be done using a simple example. Our example will illustrate the following things:</p>
<ol>
<li>Subclassing a Java class with UDD</li>
<li>Adding UDD properties to the to the subclass</li>
<li>Overloading a Java method with Matlab code</li>
<li>Directly accessing the superclass methods</li>
</ol>
<p>The example will show extending Java socket classes to provide a simple method for communication between two Matlab sessions. The protocol has been kept purposely simple and is not robust. Additional work would need to be done to create a real-life socket-based communication between Matlab systems (see for example <a rel="nofollow" target="_blank" href="http://www.mathworks.com/matlabcentral/fileexchange/24524-tcpip-communications-in-matlab">this</a> FEX submission).<br />
Today&#8217;s example consists of two subclasses: a subclass of <a target="_blank" rel="nofollow" href="http://docs.oracle.com/javase/6/docs/api/java/net/ServerSocket.html"><code>java.net.ServerSocket</code></a> and a subclass of <a target="_blank" rel="nofollow" href="http://docs.oracle.com/javase/6/docs/api/java/net/Socket.html"><code>java.net.Socket</code></a>. The protocol will be sending strings back and forth between the two sessions. In each direction the information exchange will consist of two bytes containing the string length, followed by the actual string. The entire source code can be downloaded <a target="_blank" href="/files/simple2.zip">from here</a>.</p>
<h3 id="ServerSocket">Creating the simple.ServerSocket class</h3>
<p>As in the UDD series, we will use the simple package for our classes and in this package create a <code>ServerSocket</code> class and a <code>Socket</code> class. Recall the simple package definition class is placed in a file named <i>schema.m</i> in a directory called <i>@simple</i>, placed somewhere on the Matlab path. <i>schema.m</i> consists of:</p>
<pre lang='matlab'>
function schema()
%SCHEMA  simple package definition function.
   schema.package('simple');
end
</pre>
<p>In our <code>ServerSocket</code> class we will add three UDD properties and overload two of the Java class methods. It is worth noting that our final class will have all the parent Java classes public properties and methods and if necessary we can access the parent or super class methods directly. As before, we create a subfolder of the <i>@simple</i> folder named <i>@ServerSocket</i>; in this folder we place four files:</p>
<ol>
<li><i>schema.m</i> &#8211; the class definition file</li>
<li><i>ServerSocket.m</i> &#8211; the class constructor</li>
<li><i>accept.m</i> &#8211; one of the Java methods that we will overload</li>
<li><i>bind.m</i> &#8211; the other Java method that we will overload</li>
</ol>
<p>At the beginning of our <i>schema.m</i> file, we will use the following code to subclass the Java class:</p>
<pre lang='matlab'>
function schema
%SCHEMA simple.ServerSocket class definition function.
    % parent schema.class definition
    javaPackage = findpackage('javahandle');
    javaClass = findclass(javaPackage, 'java.net.ServerSocket');
    % class package (schema.package)
    simplePackage = findpackage('simple');
    % class definition
    simpleClass = schema.class(simplePackage, 'ServerSocket', javaClass);
</pre>
<p>Here, we use <i><b>findpackage</b></i> and <i><b>findclass</b></i> to obtain the <i><b>schema.class</b></i> for the Java class that we are going to use as our parent. We then obtain a handle to the containing package, and finally use the subclass variation to define our <code>ServerSocket</code> as a variation of the Java parent&#8217;s <i><b>schema.class</b></i>.<br />
Next, in the class definition file we place the code to define the signatures for the methods we are overloading:</p>
<pre lang='matlab'>
    % accept.m overloads java accept method and adds communication protocol
    m = schema.method(simpleClass, 'accept');
    s = m.Signature;
    s.varargin    = 'off';
    s.InputTypes  = {'handle'};
    s.OutputTypes = {'string'};
    % bind.m overloads java bind method
    m = schema.method(simpleClass, 'bind');
    s = m.Signature;
    s.varargin    = 'off';
    s.InputTypes  = {'handle'};
    s.OutputTypes = {};be
</pre>
<p>Finally, we add three UDD properties to the class: The first will be used to hold a string representation of the address of our <code>ServerSocket</code>; the second will store the communication port number; the third is a handle property that will hold the reference to the socket used by the actual communication.</p>
<pre lang='matlab'>
    % holds remote address as a matlab string
    p = schema.prop(simpleClass, 'address', 'string');
    p.FactoryValue = 'localhost';
    % holds remote port as a matlab int
    p = schema.prop(simpleClass, 'port', 'int16');
    p.FactoryValue = 2222;
    % holds a handle reference to the socket created in the accept method
    p = schema.prop(simpleClass, 'socket', 'handle');
end
</pre>
<p>We now need to write our overloaded methods. The <i>bind</i> method is simple: it first creates a Java internet address using the new address and port properties; then it uses the standard Java class methods to call the superclass&#8217;s <i>bind</i> method with the specified internet address:</p>
<pre lang='matlab'>
function bind(this)
    % use the object socket and port port properties to bind this instance
    % to a address calling the superclass bind method
    inetAddress = java.net.InetSocketAddress(this.address, this.port);
    this.java.bind(inetAddress);
end
</pre>
<p>The overloaded <i>accept</i> method is a bit more complicated and crude: It starts by calling the superclass <i>accept</i> method to create a communication socket and stores the created socket in our class&#8217;s socket property. Then it goes into an infinite loop of waiting for incoming commands, uses <i><b>evalc</b></i> to execute them, and returns the captured result to the caller. The only way out of this loop is using Ctrl-C from the keyboard.</p>
<pre lang='matlab'>
function accept(this)
    % use the superclass accept
    this.socket = handle(this.java.accept);
    % infinite loop use ctrl-c to exit
    while 1
        % wait for a command then execute it capturing output
        while this.socket.getInputStream.available < 2
        end
        msb = this.socket.getInputStream.read;
        lsb = this.socket.getInputStream.read;
        numChar = 256 * msb + lsb;
        cmd = uint8(zeros(1, numChar));
        for index = 1:numChar
            cmd(index) = this.socket.getInputStream.read;
        end
        result = evalc(char(cmd));
        % send the result back to the calling system
        len = numel(result);
        msb = uint8(floor(len/256));
        lsb = uint8(mod(len,256));
        this.socket.getOutputStream.write(uint8([msb, lsb, result]));
    end
end
</pre>
<h3 id="Socket">Creating the simple.Socket class</h3>
<p>The <code>simple.Socket</code> class is created like <code>ServerSocket</code>, this time in the <i>@Socket</i> folder under the <i>@simple</i> folder. In this subclass we add properties for the address and port, just as in <code></code><code>ServerSocket</code>. We overload the superclass's <i>connect</i> method with our own variant, and add a new method to make the remote calls to the <code>ServerSocket</code> running in another Matlab instance. Beginning with the <i>schema.m</i> file we have:</p>
<pre lang="matlab">
function schema
%SCHEMA simple.Socket class definition function.
    % package definition
    simplePackage = findpackage('simple');
    javaPackage = findpackage('javahandle');
    javaClass = findclass(javaPackage, 'java.net.Socket');
    % class definition
    simpleClass = schema.class(simplePackage, 'Socket', javaClass);
    % define class methods
    % connect.m overloads java connect method
    m = schema.method(simpleClass, 'connect');
    s = m.Signature;
    s.varargin    = 'off';
    s.InputTypes  = {'handle'};
    s.OutputTypes = {};
    % remoteEval.m matlab method for remote evaluation of Matlab commands
    m = schema.method(simpleClass, 'remoteEval');
    s = m.Signature;
    s.varargin    = 'off';
    s.InputTypes  = {'handle', 'string'};
    s.OutputTypes = {'string'};
    % add properties to this class
    % holds remote address as a Matlab string
    p = schema.prop(simpleClass, 'address', 'string');
    p.FactoryValue = 'localhost';
    % holds remote port as a Matlab int
    p = schema.prop(simpleClass, 'port', 'int16');
    p.FactoryValue = 2222;
end
</pre>
<p>The class constructor <i>Socket.m</i> is simply:</p>
<pre lang="matlab">
function skt = Socket
%SOCKET constructor for the simple.Socket class
    skt = simple.Socket;
end
</pre>
<p>The overloaded <i>connect</i> method is almost identical to the overloaded bind method we used for <code>ServerSocket</code>. We form a Java internet address from our new properties and then invoke the superclass&#8217;s <i>connect</i> Java method:</p>
<pre lang="matlab">
function connect(this)
%CONNECT overload of the java.net.Socket connect method
    % use the object address and port properties to connect to the remote
    % session via the superclass connect method
    inetAddress = java.net.InetSocketAddress(this.address, this.port);
    this.java.connect(inetAddress);
end
</pre>
<p>Finally, our <i>remoteEval</i> method is very similar to the loop portion of the overloaded accept method we wrote for <code>simple.ServerSocket</code>. We take the command string input and convert it into a series of bytes prepended by the length of the string, send it to the other Matlab session and wait for a response:</p>
<pre lang='matlab'>
function result = remoteEval(this, cmd)
%REMOTEEVAL evaluate a Matlab command on a remotely connected Matlab
    % The command string is sent as a series of bytes preceded by a pair of
    % bytes which represents the length of the string
    cmd = uint8(cmd);
    len = numel(cmd);
    msb = uint8(floor(len/256));
    lsb = uint8(mod(len,256));
    this.getOutputStream.write([msb, lsb, cmd]);
    % We will expect the remote session to return a string in the same format
    % as the command
    while this.getInputStream.available < 2
    end
    msb = this.getInputStream.read;
    lsb = this.getInputStream.read;
    numChar = 256 * msb + lsb;
    result = uint8(zeros(1, numChar));
    for index = 1:numChar
        result(index) = this.getInputStream.read;
    end
    result = char(result);
end
</pre>
<h3 id="Usage">Using simple.ServerSocket and simple.Socket to communicate between Matlab sessions</h3>
<p>To use this example, add the zip contents to your Matlab path, then open an instance of Matlab and issue the following commands:</p>
<pre lang='matlab'>
>> ss = simple.ServerSocket;
>> ss.bind;
>> ss.accept;
</pre>
<p>Then open another Matlab instance and issue these commands:</p>
<pre lang='matlab'>
>> s = simple.Socket;
>> s.connect;
</pre>
<p>At this point you can send commands from this Matlab instance (the client) to the first instance (the server) using the <i>remoteEval</i> method. The command will then be transmitted to the server, executed, and the server will return the captured string result to the client:</p>
<pre lang="matlab">
>> remoteResult = s.remoteEval('pi')
remoteResult =
    3.1416
</pre>
<p>The defaults are for localhost and port 2222. These can be changed prior to using the server's <i>bind</i> method and the client's <i>connect</i> method. To keep things as simple as possible, error checking etc. has been left out, so this is just a demonstration and is far from robust.<br />
There are some things to note about our new classes. If we type <i><b>methods</b>(s)</i> or <i>s.methods</i> at the Matlab command prompt in our <code>simple.Socket</code> session we obtain:</p>
<pre lang="matlab">
>> s.methods
Methods for class simple.Socket:
Socket                     getOOBInline               isClosed                   setReuseAddress
bind                       getOutputStream            isConnected                setSendBufferSize
close                      getPort                    isInputShutdown            setSoLinger
connect                    getReceiveBufferSize       isOutputShutdown           setSoTimeout
equals                     getRemoteSocketAddress     java                       setSocketImplFactory
getChannel                 getReuseAddress            notify                     setTcpNoDelay
getClass                   getSendBufferSize          notifyAll                  setTrafficClass
getInetAddress             getSoLinger                remoteEval                 shutdownInput
getInputStream             getSoTimeout               sendUrgentData             shutdownOutput
getKeepAlive               getTcpNoDelay              setKeepAlive               toString
getLocalAddress            getTrafficClass            setOOBInline               wait
getLocalPort               hashCode                   setPerformancePreferences
getLocalSocketAddress      isBound                    setReceiveBufferSize
</pre>
<p>This shows that our <code>simple.Socket</code> class has all of the methods of the Java superclass, plus our added <code>remoteEval</code> method and the <code>java</code> method that was automatically added by Matlab. This means that all of the Java methods are methods of our class instance and the added <code>java</code> means that we can access the superclass methods from our class instance if the need arises. If we use the <i><b>struct</b></i> function which Yair has <a target="_blank" href="/articles/matlab-java-memory-leaks-performance/#struct">previously discussed</a>, we obtain:</p>
<pre lang="matlab">
>> struct(s)
ans =
              OOBInline: 0
                  Bound: 1
                Channel: []
                  Class: [1x1 java.lang.Class]
                 Closed: 0
              Connected: 1
            InetAddress: [1x1 java.net.Inet4Address]
          InputShutdown: 0
            InputStream: [1x1 java.net.SocketInputStream]
              KeepAlive: 0
           LocalAddress: [1x1 java.net.Inet4Address]
              LocalPort: 51269
     LocalSocketAddress: [1x1 java.net.InetSocketAddress]
         OutputShutdown: 0
           OutputStream: [1x1 java.net.SocketOutputStream]
      ReceiveBufferSize: 8192
    RemoteSocketAddress: [1x1 java.net.InetSocketAddress]
           ReuseAddress: 0
         SendBufferSize: 8192
               SoLinger: -1
              SoTimeout: 0
             TcpNoDelay: 0
           TrafficClass: 0
                address: 'localhost'
                   port: 2222
</pre>
<p>We see that we have access to all of the public properties of the Java superclass, as well as the UDD properties that we have added.</p>
<h3 id="Conclusion">Conclusion</h3>
<p>At the beginning of this post I said that this would be a simple non-robust communications method. In order to make this anything more than that, a number of things would need to be implemented, for example:</p>
<ul>
<li>Improve the <i>accept</i> method to exit after a timeout or when a connection has been made and then terminated</li>
<li>Add checksums and timeouts for communication to determine the reliability of the communication</li>
<li>Add a retry request protocol for instances of communication failure</li>
<li>Add support for any serializable Matlab type, not just strings</li>
</ul>
<p>The intent here was just to show that extending Java classes with Matlab is possible, relatively simple, and can be extremely useful. After all, with over 10 million Java developers out there, chances are that somebody somewhere has already posted a Java class that answers your exact need, or at least close enough that it can be used in Matlab with only some small modifications.</p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/extending-a-java-class-with-udd">Extending a Java class with UDD</a> appeared first on <a rel="nofollow" href="https://undocumentedmatlab.com">Undocumented Matlab</a>.</p>
<div class='yarpp-related-rss'>
<h3>Related posts:</h3><ol>
<li><a href="https://undocumentedmatlab.com/articles/java-class-access-pitfalls" rel="bookmark" title="Java class access pitfalls">Java class access pitfalls </a> <small>There are several potential pitfalls when accessing Matlab classes from Matlab. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/accessing-internal-java-class-members" rel="bookmark" title="Accessing internal Java class members">Accessing internal Java class members </a> <small>Java inner classes and enumerations can be used in Matlab with a bit of tweaking. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/udd-and-java" rel="bookmark" title="UDD and Java">UDD and Java </a> <small>UDD provides built-in convenience methods to facilitate the integration of Matlab UDD objects with Java code - this article explains how...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/creating-a-simple-udd-class" rel="bookmark" title="Creating a simple UDD class">Creating a simple UDD class </a> <small>This article explains how to create and test custom UDD packages, classes and objects...</small></li>
</ol>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://undocumentedmatlab.com/articles/extending-a-java-class-with-udd/feed</wfw:commentRss>
			<slash:comments>14</slash:comments>
		
		
			</item>
		<item>
		<title>Creating a simple UDD class</title>
		<link>https://undocumentedmatlab.com/articles/creating-a-simple-udd-class?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=creating-a-simple-udd-class</link>
					<comments>https://undocumentedmatlab.com/articles/creating-a-simple-udd-class#comments</comments>
		
		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Wed, 23 Feb 2011 17:29:05 +0000</pubDate>
				<category><![CDATA[Guest bloggers]]></category>
		<category><![CDATA[Medium risk of breaking in future versions]]></category>
		<category><![CDATA[Stock Matlab function]]></category>
		<category><![CDATA[Undocumented feature]]></category>
		<category><![CDATA[Undocumented function]]></category>
		<category><![CDATA[Donn Shull]]></category>
		<category><![CDATA[Pure Matlab]]></category>
		<category><![CDATA[schema]]></category>
		<category><![CDATA[schema.class]]></category>
		<category><![CDATA[schema.prop]]></category>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=2130</guid>

					<description><![CDATA[<p>This article explains how to create and test custom UDD packages, classes and objects</p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/creating-a-simple-udd-class">Creating a simple UDD class</a> appeared first on <a rel="nofollow" href="https://undocumentedmatlab.com">Undocumented Matlab</a>.</p>
<div class='yarpp-related-rss'>
<h3>Related posts:</h3><ol>
<li><a href="https://undocumentedmatlab.com/articles/extending-a-java-class-with-udd" rel="bookmark" title="Extending a Java class with UDD">Extending a Java class with UDD </a> <small>Java classes can easily be extended in Matlab, using pure Matlab code. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/setting-class-property-types" rel="bookmark" title="Setting class property types">Setting class property types </a> <small>Matlab's class properties have a simple and effective mechanism for setting their type....</small></li>
<li><a href="https://undocumentedmatlab.com/articles/handle-object-as-default-class-property-value" rel="bookmark" title="Handle object as default class property value">Handle object as default class property value </a> <small>MCOS property initialization has a documented but unexpected behavior that could cause many bugs in user code. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/simple-gui-tabs-for-advanced-matlab-trading-app" rel="bookmark" title="Simple GUI Tabs for Advanced Matlab Trading App">Simple GUI Tabs for Advanced Matlab Trading App </a> <small>A new File Exchange utility enables to easily design GUI tabs using Matlab's GUIDE...</small></li>
</ol>
</div>
]]></description>
										<content:encoded><![CDATA[<p><i>Once again I welcome guest blogger <a target="_blank" rel="nofollow" href="http://aetoolbox.com/">Donn Shull</a>, who continues his multi-part series about Matlab&#8217;s undocumented UDD objects.</i></p>
<h3 id="package">Creating a new UDD package</h3>
<p>To illustrate the construction of UDD classes with Matlab m-code, let&#8217;s create a simple class belonging to a new simple package. Our class will have two properties: a <b>Name</b> property of type string, and a <b>Value</b> property of type double. This class will have two methods that will illustrate overloading the built-in <i><b>disp</b></i> function, and using a <i>dialog</i> method to present a GUI. Our class will also have one event, to demonstrate UDD event handling.<br />
To create this simple UDD class we need two directories and five m-files (downloadable <a href="/files/simple.zip">here</a>): The parent directory needs to be a directory on the Matlab path. A subdirectory of the parent directory is named with the symbol @ followed by our UDD package name &#8211; this is the package directory. In this example, the subdirectory is called @simple.<br />
Within the @simple directory, place a file named <i>schema.m</i>, which is the package definition file. This is a very simple file, that merely calls <i><b>schema.package</b></i> to create a new package called &#8216;simple&#8217;:</p>
<pre lang="matlab">
function schema()
%SCHEMA simple package definition function.
   schema.package('simple');
end
</pre>
<p>If you place additional m-files in the package directory they will be called package function files. Those files will have package scope and can be accessed with the notation <code>packagename.functionname</code>. We will not use package functions in this example, so we will only have the schema.m file shown above.</p>
<h3 id="class">Creating a new UDD class</h3>
<p>Next, create another subdirectory beneath @simple, named with an @ symbol followed by the UDD class name. In this example we will create the directory @object (i.e., /@simple/@object/). We place four m-files in this directory:<br />
The first file is yet another schema.m file, which is the class-definition file:</p>
<pre lang="matlab">
function schema()
%SCHEMA  simple.object class definition function.
   % Get a handle to the 'simple' package
   simplePackage = findpackage('simple');
   % Create a base UDD object
   simpleClass = schema.class(simplePackage, 'object');
   % Define the class methods:
   % dialog.m method
   m = schema.method(simpleClass, 'dialog');
   s = m.Signature;
   s.varargin    = 'off';
   s.InputTypes  = {'handle'};
   s.OutputTypes = {};
   % disp.m method
   m = schema.method(simpleClass, 'disp');
   s = m.Signature;
   s.varargin    = 'off';
   s.InputTypes  = {'handle'};
   s.OutputTypes = {};
   % Define the class properties:
   schema.prop(simpleClass, 'Name', 'string');
   schema.prop(simpleClass, 'Value', 'double');
   % Define the class events:
   schema.event(simpleClass, 'simpleEvent');
end
</pre>
<p>Here, we used the built-in <i><b>findpackage</b></i> function to identify our base package (<code>simple</code>). Then we used <i><b>schema.class</b></i> to define a new class &#8216;object&#8217; within that base package. We next defined two class methods, two properties and finally an event.</p>
<h3 id="methods">Defining class methods</h3>
<p>It is not mandatory to define the method signatures as we have done in our class definition file. If you omit the method signature definitions, Matlab will automatically generate default signatures that will actually work in most applications. However, I believe that it is bad practice to omit the method signature definitions in a class definition file, and there are cases where your classes will not work as you have intended if you omit them.<br />
Now, place a file named object.m in the @object directory. This file contains the class constructor method, which is executed whenever a new instance object of the <code>simple.object</code> class is created:</p>
<pre lang="matlab">
function simpleObject = object()
%OBJECT constructor for the simple.object class
%
%   SIMPLEOBJECT = OBJECT(NAME, VALUE) creates an instance of the
%   simple.object class with the Name property set to NAME and the
%   Value property set VALUE
%
%   SIMPLEOBJECT = OBJECT(NAME) creates an instance of the simple.object
%   class with the Name property set to NAME. The Value property will be
%   given the default value of 0.
%
%   SIMPLEOBJECT = OBJECT creates an instance of the simple.object class
%   and executes the simple.object dialog method to open a GUI for editing
%   the Name and Value properties.
%
%   INPUTS:
%       NAME          : string
%       VALUE         : double
%
%   OUTPUTS:
%       SIMPLEOBJECT  : simple.object instance
   simpleObject = simple.object;
   switch nargin
      case 0
         simpleObject.dialog;
      case 1
         simpleObject.Name = name;
      case 2
         simpleObject.Name = name;
         simpleObject.Value = value;
   end
end
</pre>
<p>The two other m-files in the @object directory will be our class methods &#8211; a single file for each method. In our case they are disp.m and dialog.m:</p>
<pre lang="matlab">
function disp(self)
%DISP overloaded object disp method
%
%   DISP(SELF) or SELF.DISP uses the MATLAB builtin DISP function
%   to display the Name and Value properties of the object.
%
%   INPUTS:
%       SELF  : simple.object instance
   builtin('disp', sprintf('  Name: %s\n Value: %f', self.Name, self.Value));
   %Alternative: fprintf('\n  Name: %s\n Value: %f', self.Name, self.Value));
end
</pre>
<p>And the dialog method (in dialog.m):</p>
<pre lang="matlab">
function dialog(self)
%DIALOG dialog method for simple.object for use by openvar
%
%   DIALOG(SELF) or SELF.DIALOG where self is the name of the simple.object
%   instance opens a gui to edit the Name and Value properties of self.
%
%   INPUTS:
%       SELF  : simple.object
   dlgValues = inputdlg({'Name:', 'Value:'}, 'simple.object', 1, {self.Name, mat2str(self.Value)});
   if ~isempty(dlgValues)
      self.Name = dlgValues{1};
      self.Value = eval(dlgValues{2});
   end
end
</pre>
<h3 id="testing">Testing our new class</h3>
<p>Now let&#8217;s test our new class by creating an instance without using any input arguments</p>
<pre lang="matlab">a = simple.object</pre>
<p>This calls the object&#8217;s constructor method, which launches the input dialog GUI:<br />
<center><figure style="width: 181px" class="wp-caption aligncenter"><img decoding="async" alt="UDD simple class GUI" src="https://undocumentedmatlab.com/images/UDD_simple_object_1.jpg" title="UDD simple class GUI" width="181" height="163" /><figcaption class="wp-caption-text">UDD simple class GUI</figcaption></figure></center><br />
Note the default empty string value for the <b>Name</b> property, and the default zero value for the <b>Value</b> property. In one of the following articles I will show how to control property values. For now let&#8217;s assign &#8216;a&#8217; to <b>Name</b> and 1 to <b>Value</b> using the GUI. Selecting OK updates our object and closes the GUI. Matlab then calls the object&#8217;s <i>disp</i> method to display our object in the command window:</p>
<pre lang="matlab">
a =
  Name: a
 Value: 1.000000
</pre>
<p>We can reopen our object&#8217;s GUI using three methods: The most obvious is to invoke the <i>dialog</i> method using <code>a.dialog</code> or <code>dialog(a)</code>. Alternately, double click on a in the workspace explorer window &#8211; Matlab will automatically call the built-in <i><b>openvar</b></i> function with the variable name and value as arguments. Which leads us to the third method &#8211; simply call <i><b>openvar</b>(&#8216;a&#8217;, a)</i> directly:</p>
<pre lang="matlab">
% Alternatives for programmatically displaying the GUI
a.dialog();  % or simply: a.dialog
dialog(a);
openvar('a',a);
</pre>
<h3 id="help">Accessing UDD help</h3>
<p>You may have noticed that in our constructor and method files we have included help text. This is good practice for all Matlab files in general, and UDD is no exception. We can access the UDD class help as follows:</p>
<pre lang="text">
> help simple.object
 OBJECT constructor for the simple.object class
    SIMPLEOBJECT = OBJECT(NAME, VALUE) creates an instance of the
    simple.object class with the Name property set to NAME and the
    Value property set VALUE
    SIMPLEOBJECT = OBJECT(NAME) creates an instance of the simple.object
    class with the Name property set to NAME. The Value property will be
    given the default value of 0.
    SIMPLEOBJECT = OBJECT creates an instance of the simple.object class
    and executes the simple.object dialog method to open a GUI for editing
    the Name and Value properties.
    INPUTS:
        NAME          : string
        VALUE         : double
    OUTPUTS:
        SIMPLEOBJECT  : simple.object instance
>> help simple.object.disp
 DISP overloaded object disp method
    DISP(SELF) or SELF.DISP uses the MATLAB builtin DISP function
    to display the Name and Value properties of the object.
    INPUTS:
        SELF  : simple.object instance
</pre>
<p>One of the best ways to learn how Matlab works is to examine code written by the Matlab development team. <i><b>openvar</b></i> is a good example: By looking at it we can see that if a variable is a <i><b>handle</b></i> object and is opaque, then <i><b>openvar</b></i> will check to see if it has a <i>dialog</i> method. If so, it will use that to open the variable for editing. With this information we can guess that MCOS, UDD and even java objects can all launch their own dialog editors simply by having an appropriate <i>dialog</i> method.<br />
An excellent source of UDD information is available in the Matlab toolbox folders. The base Matlab toolbox contains sixteen different UDD packages to explore. Yummy!<br />
In the next article of this UDD series we will look at creating hierarchical structures using our <code>simple.object</code> and a unique UDD method.</p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/creating-a-simple-udd-class">Creating a simple UDD class</a> appeared first on <a rel="nofollow" href="https://undocumentedmatlab.com">Undocumented Matlab</a>.</p>
<div class='yarpp-related-rss'>
<h3>Related posts:</h3><ol>
<li><a href="https://undocumentedmatlab.com/articles/extending-a-java-class-with-udd" rel="bookmark" title="Extending a Java class with UDD">Extending a Java class with UDD </a> <small>Java classes can easily be extended in Matlab, using pure Matlab code. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/setting-class-property-types" rel="bookmark" title="Setting class property types">Setting class property types </a> <small>Matlab's class properties have a simple and effective mechanism for setting their type....</small></li>
<li><a href="https://undocumentedmatlab.com/articles/handle-object-as-default-class-property-value" rel="bookmark" title="Handle object as default class property value">Handle object as default class property value </a> <small>MCOS property initialization has a documented but unexpected behavior that could cause many bugs in user code. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/simple-gui-tabs-for-advanced-matlab-trading-app" rel="bookmark" title="Simple GUI Tabs for Advanced Matlab Trading App">Simple GUI Tabs for Advanced Matlab Trading App </a> <small>A new File Exchange utility enables to easily design GUI tabs using Matlab's GUIDE...</small></li>
</ol>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://undocumentedmatlab.com/articles/creating-a-simple-udd-class/feed</wfw:commentRss>
			<slash:comments>6</slash:comments>
		
		
			</item>
		<item>
		<title>Introduction to UDD</title>
		<link>https://undocumentedmatlab.com/articles/introduction-to-udd?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=introduction-to-udd</link>
					<comments>https://undocumentedmatlab.com/articles/introduction-to-udd#comments</comments>
		
		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Wed, 16 Feb 2011 18:00:09 +0000</pubDate>
				<category><![CDATA[Guest bloggers]]></category>
		<category><![CDATA[Handle graphics]]></category>
		<category><![CDATA[Listeners]]></category>
		<category><![CDATA[Medium risk of breaking in future versions]]></category>
		<category><![CDATA[Undocumented feature]]></category>
		<category><![CDATA[Undocumented function]]></category>
		<category><![CDATA[Donn Shull]]></category>
		<category><![CDATA[Internal component]]></category>
		<category><![CDATA[Listener]]></category>
		<category><![CDATA[Pure Matlab]]></category>
		<category><![CDATA[schema]]></category>
		<category><![CDATA[schema.class]]></category>
		<category><![CDATA[schema.prop]]></category>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=2036</guid>

					<description><![CDATA[<p>UDD classes underlie many of Matlab's handle-graphics objects and functionality. This article introduces these classes.</p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/introduction-to-udd">Introduction to UDD</a> appeared first on <a rel="nofollow" href="https://undocumentedmatlab.com">Undocumented Matlab</a>.</p>
<div class='yarpp-related-rss'>
<h3>Related posts:</h3><ol>
<li><a href="https://undocumentedmatlab.com/articles/udd-properties" rel="bookmark" title="UDD Properties">UDD Properties </a> <small>UDD provides a very convenient way to add customizable properties to existing Matlab object handles...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/creating-a-simple-udd-class" rel="bookmark" title="Creating a simple UDD class">Creating a simple UDD class </a> <small>This article explains how to create and test custom UDD packages, classes and objects...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/udd-events-and-listeners" rel="bookmark" title="UDD Events and Listeners">UDD Events and Listeners </a> <small>UDD event listeners can be used to listen to property value changes and other important events of Matlab objects...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/new-information-on-hg2" rel="bookmark" title="New information on HG2">New information on HG2 </a> <small>More information on Matlab's new HG2 object-oriented handle-graphics system...</small></li>
</ol>
</div>
]]></description>
										<content:encoded><![CDATA[<p><i>I would like to welcome guest blogger <a target="_blank" rel="nofollow" href="http://aetoolbox.com/">Donn Shull</a>. Donn will present a series of articles about UDD classes and objects, on which many undocumented Matlab features and functions are based.</i></p>
<h3 id="Background">Background on UDD</h3>
<p>Matlab has used objects for a long time. In R8 (Matlab 5.0), their first user accessible class system was introduced. Andy Register wrote a <a target="_blank" rel="nofollow" href="http://www.scitechpub.com/catalog/product_info.php?products_id=386">detailed reference</a> on using this system. Although that original system is obsolete, it is still available in R24 (R2010b).<br />
UDD objects (also referred to as <i>schema</i> objects) were introduced with R12 (Matlab 6.0). UDD has been a foundation platform for a number of core Matlab technologies. MathWorks have consistently maintained that UDD is only meant for internal development and not for Matlab users. So, while UDD has no formal documentation, there are plenty of examples and tools to help us learn about it.<br />
It is somewhat odd that despite Matlab&#8217;s new object-oriented system (<a target="_blank" rel="nofollow" href="http://www.mathworks.com/help/techdoc/matlab_oop/bri1rtu.html">MCOS</a>)&#8217;s introduction 3 years ago, and the <a target="_blank" href="/articles/tag/hg2/">ongoing concurrent development of HG2</a> classes, the older-technology UDD is still being actively developed, as evidenced by the increasing number of UDD classes in recent releases. More background on the differences between these different sets of classes can be found <a target="_blank" href="/articles/new-information-on-hg2/">here</a>.</p>
<h3 id="WhyBother">Why should we bother learning UDD?</h3>
<p>There are some things to consider before deciding if you want to spend the time to learn about the UDD class system:</p>
<h4 id="Pros">The case against studying UDD classes</h4>
<ul>
<li>There is no documentation from The MathWorks for these classes</li>
<li>You will not get any help from The MathWorks in applying these classes</li>
<li>The UDD system is now more than a decade old and may be phased out in future Matlab releases (perhaps in HG2?)</li>
</ul>
<h4 id="Cons">The case for studying UDD classes</h4>
<ul>
<li>UDD is currently the foundation of handle graphics, Java integration, COM, and Simulink</li>
<li>The m code versions of UDD may be considered a forerunner of the newer MCOS class system</li>
<li>To avoid memory leaks when using Callbacks in GUI applications you currently need to use UDD</li>
<li>UDD techniques facilitate Matlab interaction with Java GUIs</li>
<li>UDD directly supports the Matlab style method invocation as well as dot notation for methods without the need to write subsasgn and subsref routines</li>
</ul>
<h3 id="Tools">Tools for Learning about UDD</h3>
<p>We start by describing some undocumented Matlab tools that will help us investigate and understand UDD classes.</p>
<ul>
<li><i><b>findpackage</b></i> &#8211; All UDD Classes are defined as members of a package. findpackage takes the package name as an input argument and returns a schema.package object which provides information about the package</li>
<li><i><b>findclass</b></i> &#8211; This method of the schema.package object returns a schema.class object of the named class if the class exists in the package</li>
<li><i><b>classhandle</b></i> &#8211; For a given UDD object <i><b>classhandle</b></i> returns a schema.class object with information about the class. <i><b>classhandle</b></i> and <i><b>findclass</b></i> are two ways of getting the same information about a UDD class. <i><b>findclass</b></i> works with a <i><b>schema.package</b></i> object and a class name and does not require an instance of the class. <i><b>classhandle</b></i> works with an instance of a class</li>
<li><i><b>findprop</b></i> &#8211; This method of the schema.class object returns a schema.prop object which contains information about the named property</li>
<li><i><b>findevent</b></i> &#8211; This method of the schema.class object returns a schema.prop object which contains information about the named event</li>
<li><i><b>handle</b></i> &#8211; handle is a multifaceted and unique term for The MathWorks. There are both UDD and MCOS handle classes. There is a UDD handle package. In terms of the tools we need, <i><b>handle</b></i> is also an undocumented function which converts a numeric handle into a UDD handle object. Depending on your background you may want to think of <i><b>handle</b></i> as a cast operator which casts a numeric handle into a UDD object.</li>
<li><i><b>methods</b></i> &#8211; This is used to display the methods of an object</li>
<li><i><b>methodsview</b></i> &#8211; Provides a graphic display of an objects methods</li>
<li><a target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/17935-uiinspect-display-methods-properties-callbacks-of-an-object"><i><b>uiinspect</b></i></a> &#8211; Yair Altman&#8217;s object inspection tool, which can be used for COM, Java and Matlab classes (<i><b>uiinspect</b> will be described in a separate article in the near future</i>).</li>
</ul>
<p>Before we apply these tools we need to discuss the basic structure of UDD classes. Let&#8217;s compare them with the newer, well documented MCOS classes:<br />
MCOS classes can be defined simply as a standalone class or scoped by placing the class in a package or a hierarchy of packages. With UDD, all classes must be defined in a package. UDD Packages are not hierarchical so a UDD package may not contain other packages. UDD classes can always be instantiated with syntax of packageName.className. By default MCOS classes are value classes. With MCOS you can subclass the handle class to create handle classes. UDD classes are handle classes by default, but it is possible to create UDD value classes.</p>
<h3 id="Exploring">Exploring some important built-in UDD Classes</h3>
<p>The current versions of Matlab include a number of built-in UDD packages. We will use our new tools to see what we can learn about these packages. Let us begin by inspecting the two packages that form the basis of the UDD class system.</p>
<h4 id="schema">The schema package</h4>
<p>The built-in schema package contains the classes for creating user written UDD classes. It also is used to provide meta information about UDD classes. Using <i><b>findpackage</b></i> we will obtain a schema.package object for the schema package and then use it obtain information about the classes it contains:</p>
<pre lang="matlab">
>> pkg = findpackage('schema')
pkg =
        schema.package
>> pkg.get
               Name: 'schema'
    DefaultDatabase: [1x1 handle.Database]
            Classes: [9x1 schema.class]
          Functions: [0x1 handle]
        JavaPackage: ''
         Documented: 'on'
</pre>
<p>Note that here we have used the dot-notation pkg.<i><b>get</b></i> &#8211; we could also have used the Matlab notation <i><b>get</b>(pkg)</i> instead.<br />
We have now learned that that there are nine classes in the schema package. The information about them in a schema package&#8217;s <b>Classes</b> property. To see the information about individual classes we inspect this property:</p>
<pre lang="matlab">
>> pkg.Classes(1).get
               Name: 'class'
            Package: [1x1 schema.package]
        Description: ''
        AccessFlags: {0x1 cell}
             Global: 'off'
             Handle: 'on'
       Superclasses: [0x1 handle]
    SuperiorClasses: {0x1 cell}
    InferiorClasses: {0x1 cell}
            Methods: [4x1 schema.method]
         Properties: [13x1 schema.prop]
             Events: []
     JavaInterfaces: {0x1 cell}
</pre>
<p>Not surprisingly, the first class in the schema.package is &#8216;class&#8217; itself. Here we can see that schema.class has 4 methods and 13 properties. We can also see that the schema.class objects have a <b>Name</b> property. Let&#8217;s use that information to list all the classes in the schema package:</p>
<pre lang="matlab">
>> names = cell(numel(pkg.Classes), 1);
>> for index = 1:numel(names), names{index} = pkg.Classes(index).Name; end;
>> names
names =
    'class'
    'method'
    'signature'
    'package'
    'event'
    'prop'
    'type'
    'EnumType'
    'UserType'
</pre>
<p>These are the base classes for the UDD package schema. To illustrate a different way to get information, let&#8217;s use the <i><b>findclass</b></i> method of schema.package to get information about the schema.prop class:</p>
<pre lang="matlab">
>> p = findclass(pkg, 'prop')
p =
        schema.class
>> get(p)
               Name: 'prop'
            Package: [1x1 schema.package]
        Description: ''
        AccessFlags: {0x1 cell}
             Global: 'off'
             Handle: 'on'
       Superclasses: [0x1 handle]
    SuperiorClasses: {0x1 cell}
    InferiorClasses: {0x1 cell}
            Methods: [2x1 schema.method]
         Properties: [9x1 schema.prop]
             Events: []
     JavaInterfaces: {0x1 cell}
</pre>
<h4 id="handle">The handle package</h4>
<p>The second basic UDD package is the handle package. Handle holds a special place in Matlab and has multiple meanings: Handle is a type of Matlab object that is passed by reference; <i><b>handle</b></i> is a function which converts a numeric handle to an object; handle is an abstract object in the new MCOS class system and handle is also a UDD package as well as the default type for UDD objects.<br />
There is an interesting connection between UDD and MCOS that involves handle. In Matlab releases R12 through R2007b, the UDD handle package had up to 12 classes and did not have any package functions (package functions are functions which are scoped to a package; their calling syntax is [outputs] = packageName.<i>functionName(inputs)</i>).<br />
Beginning with the formal introduction of MCOS in R2008a, the abstract MCOS class handle was introduced. The MCOS handle class has 12 methods. It also turns out that beginning with R2008a, the UDD handle package has 12 package functions which are the MCOS handle methods.<br />
The 12 UDD classes in the handle package fall into two groups: The database and transaction classes work with the schema.package to provide a UDD stack mechanism; the listener and family of EventData classes work with schema.event to provide the UDD event mechanism:</p>
<pre lang="matlab">
>> pkg = findpackage('handle')
pkg =
        schema.package
>> pkg.get
               Name: 'handle'
    DefaultDatabase: [1x1 handle.Database]
            Classes: [12x1 schema.class]
          Functions: [12x1 schema.method]
        JavaPackage: ''
         Documented: 'on'
>> names = cell(numel(pkg.Classes), 1);
>> for index = 1:numel(names), names{index} = pkg.Classes(index).Name; end
>> names
names =
    'Operation'
    'transaction'
    'Database'
    'EventData'
    'ClassEventData'
    'ChildEventData'
    'ParentEventData'
    'PropertyEventData'
    'PropertySetEventData'
    'listener'
    'JavaEventData'
    'subreference__'
</pre>
<h4 id="hg">The hg package</h4>
<p>Arguably the most important UDD package in Matlab is the handle graphics package hg. Among the built-in UDD packages, hg is unique in several respects. As Matlab has evolved from R12 through R2011a, the number of default classes in the hg package has nearly doubled going from 17 classes to 30 (UDD has a mechanism for automatically defining additional classes as needed during run-time).<br />
The hg package contains a mixture of Global and non Global classes. These classes return a numeric handle, unless they have been created using package scope. The uitools m-file package provides a great example of extending built-in UDD classes with user written m-file UDD classes.<br />
The UDD class for a Handle-Graphics object can be obtained either by explicitly creating it with the hg package, or using the <i><b>handle</b></i> function on the numeric handle obtained from normal hg object creation. Using figure as an example, you can either use figh = hg.figure or fig = <i><b>figure</b></i> followed by figh = <i><b>handle</b></i>(fig):</p>
<pre lang="matlab">
>> pkg = findpackage('hg')
pkg =
        schema.package
>> pkg.get
               Name: 'hg'
    DefaultDatabase: [1x1 handle.Database]
            Classes: [30x1 schema.class]
          Functions: [0x1 handle]
        JavaPackage: 'com.mathworks.hg'
         Documented: 'on'
>> for index = 1:numel(names), names{index} = pkg.Classes(index).Name; end
>> names
names =
    'GObject'
    'root'
    'LegendEntry'
    'Annotation'
    'figure'
    'uimenu'
    'uicontextmenu'
    'uicontrol'
    'uitable'
    'uicontainer'
    'hgjavacomponent'
    'uipanel'
    'uiflowcontainer'
    'uigridcontainer'
    'uitoolbar'
    'uipushtool'
    'uisplittool'
    'uitogglesplittool'
    'uitoggletool'
    'axes'
    'hggroup'
    'text'
    'line'
    'patch'
    'surface'
    'rectangle'
    'light'
    'image'
    'hgtransform'
    'uimcosadapter'
</pre>
<p>So far we have just explored the very basic concepts of UDD. You may well be wondering what the big fuss is about, since the information presented so far does not have any immediately-apparent benefits.<br />
The following set of articles will describe more advanced topics in UDD usage and customizations, using the building blocks presented today. Hopefully you will quickly understand how using UDD can help achieve some very interesting stuff with Matlab.</p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/introduction-to-udd">Introduction to UDD</a> appeared first on <a rel="nofollow" href="https://undocumentedmatlab.com">Undocumented Matlab</a>.</p>
<div class='yarpp-related-rss'>
<h3>Related posts:</h3><ol>
<li><a href="https://undocumentedmatlab.com/articles/udd-properties" rel="bookmark" title="UDD Properties">UDD Properties </a> <small>UDD provides a very convenient way to add customizable properties to existing Matlab object handles...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/creating-a-simple-udd-class" rel="bookmark" title="Creating a simple UDD class">Creating a simple UDD class </a> <small>This article explains how to create and test custom UDD packages, classes and objects...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/udd-events-and-listeners" rel="bookmark" title="UDD Events and Listeners">UDD Events and Listeners </a> <small>UDD event listeners can be used to listen to property value changes and other important events of Matlab objects...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/new-information-on-hg2" rel="bookmark" title="New information on HG2">New information on HG2 </a> <small>More information on Matlab's new HG2 object-oriented handle-graphics system...</small></li>
</ol>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://undocumentedmatlab.com/articles/introduction-to-udd/feed</wfw:commentRss>
			<slash:comments>7</slash:comments>
		
		
			</item>
		<item>
		<title>Undocumented cursorbar object</title>
		<link>https://undocumentedmatlab.com/articles/undocumented-cursorbar-object?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=undocumented-cursorbar-object</link>
					<comments>https://undocumentedmatlab.com/articles/undocumented-cursorbar-object#comments</comments>
		
		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Wed, 29 Sep 2010 18:00:12 +0000</pubDate>
				<category><![CDATA[Handle graphics]]></category>
		<category><![CDATA[High risk of breaking in future versions]]></category>
		<category><![CDATA[Stock Matlab function]]></category>
		<category><![CDATA[Undocumented function]]></category>
		<category><![CDATA[Hidden property]]></category>
		<category><![CDATA[Internal component]]></category>
		<category><![CDATA[Pure Matlab]]></category>
		<category><![CDATA[schema.class]]></category>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=1903</guid>

					<description><![CDATA[<p>Matlab's internal undocumented graphics.cursorbar object can be used to present dynamic data-tip cross-hairs</p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/undocumented-cursorbar-object">Undocumented cursorbar object</a> appeared first on <a rel="nofollow" href="https://undocumentedmatlab.com">Undocumented Matlab</a>.</p>
<div class='yarpp-related-rss'>
<h3>Related posts:</h3><ol>
<li><a href="https://undocumentedmatlab.com/articles/getundoc-get-undocumented-object-properties" rel="bookmark" title="getundoc &#8211; get undocumented object properties">getundoc &#8211; get undocumented object properties </a> <small>getundoc is a very simple utility that displays the hidden (undocumented) properties of a specified handle object....</small></li>
<li><a href="https://undocumentedmatlab.com/articles/handle-object-as-default-class-property-value" rel="bookmark" title="Handle object as default class property value">Handle object as default class property value </a> <small>MCOS property initialization has a documented but unexpected behavior that could cause many bugs in user code. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/accessing-private-object-properties" rel="bookmark" title="Accessing private object properties">Accessing private object properties </a> <small>Private properties of Matlab class objects can be accessed (read and write) using some undocumented techniques. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/general-use-object-copy" rel="bookmark" title="General-use object copy">General-use object copy </a> <small>Matlab's dual internal serialization/deserialization functions can be used to create duplicates of any object. ...</small></li>
</ol>
</div>
]]></description>
										<content:encoded><![CDATA[<p>Every now and then, I stumble on a Matlab feature that looks interesting and potentially useful and has existed for many previous Matlab releases, yet remains undocumented and unsupported. Today I present one such object, Matlab&#8217;s <i><b>graphics.cursorbar</b></i>.<br />
The <i><b>graphics.cursorbar</b></i> object answers a very basic need that is often encountered in graph exploration: displaying data values together with horizontal/vertical cross-hairs, similarly to <i><b>ginput</b></i>.<br />
While Matlab has provided the data-cursor mode for a long time, the cross-hair feature is still missing as of R2010b. Many CSSM newsgroup readers have asked about this missing feature. Some recent examples: <a target="_blank" rel="nofollow" href="https://www.mathworks.com/matlabcentral/newsreader/view_thread/278992">here</a>, <a target="_blank" rel="nofollow" href="http://www.mathworks.cn/matlabcentral/newsreader/view_thread/289787">here</a>, and <a target="_blank" rel="nofollow" href="http://www.mathworks.cn/matlabcentral/newsreader/view_thread/288484">here</a>.</p>
<h3 id="DataMatrix">DataMatrix</h3>
<p>To answer this need I have created the <a target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/16181-datamatrix"><i><b>DataMatrix</b></i> utility</a>, which is available on the Matlab File Exchange:<br />
<center><figure style="width: 450px" class="wp-caption aligncenter"><img decoding="async" alt="DataMatrix: customizable data tooltip &#038; cross-hairs" src="https://undocumentedmatlab.com/images/datamatrix.png" title="DataMatrix: customizable data tooltip &#038; cross-hairs" width="450" height="398" /><figcaption class="wp-caption-text">DataMatrix: customizable data tooltip & cross-hairs</figcaption></figure></center><br />
<i><b>DataMatrix</b></i> displays matlab&#8217;s standard data-cursor tooltip together with dotted cross-hairs, both of which move with the mouse pointer. <i><b>DataMatrix</b></i> is actually based mostly on fully-documented stuff: the undocumented aspects are secondary to the main program flow and mostly just ensure old releases compatibility and correct behavior in the presence of some figure modes.</p>
<h3 id="Cursorbar">graphics.cursorbar</h3>
<p>When I created <i><b>DataMatrix</b></i> in 2007, I had no idea that <i><b>graphics.cursorbar</b></i> already existed. <i><b>graphics.cursorbar</b></i> is an internal Matlab object, that is undocumented and unsupported. It has several advantages over <i><b>DataMatrix</b></i>, being more customizable in the cross-hairs and data marker, although not enabling to customize the tooltip text nor to present both cross-hairs (only horizontal/vertical, not both). It is one of the earliest examples of Matlab&#8217;s old class system (<i><b>schema</b></i>-based).<br />
We initialize a <i><b>graphics.cursorbar</b></i> object by supplying an axes (not very useful) or plot-line handle (more useful). The cursorbar handle can be customized using properties such as <b>BottomMarker, TopMarker, CursorLineColor, CursorLineStyle, CursorLineWidth, TargetMarkerSize, TargetMarkerStyle, ShowText, Orientation, Position</b> (Position is a hidden property) etc., as well as the regular HG properties (<b>UserData, Visibility, Parent</b> etc.).<br />
Once the cursor-bar is created, it can be dragged and moved via the mouse cursor, as the following code snippet and animated gif show:</p>
<pre lang="matlab">
t=0:.01:7; hp=plot(t,sin(t));
hCursorbar = graphics.cursorbar(hp); drawnow
hCursorbar.CursorLineColor = [.9,.3,.6]; % default=[0,0,0]='k'
hCursorbar.CursorLineStyle = '-.';       % default='-'
hCursorbar.CursorLineWidth = 2.5;        % default=1
hCursorbar.Orientation = 'vertical';     % =default
hCursorbar.TargetMarkerSize = 12;        % default=8
hCursorbar.TargetMarkerStyle = 'o';      % default='s' (square)
</pre>
<p><center><figure style="width: 300px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" alt="Matlab's internal cursorbar object" src="https://undocumentedmatlab.com/images/colorbar_animated.gif" title="Matlab's internal cursorbar object" width="300" height="225" /><figcaption class="wp-caption-text">Matlab's internal cursorbar object</figcaption></figure></center><br />
Comments within the internal code (%matlabroot%\toolbox\matlab\graphics\@graphics\@cursorbar\*.m) suggest that <i><b>graphics.cursorbar</b></i> has been around since 2003 at least, although I have not checked such old releases. The presented tooltip resembles one of the old data tips, not one of the modern ones. In addition, as far as I can tell, <i><b>graphics.cursorbar</b></i> is not used within the Matlab code corpus. For these reasons it would not surprise me at all to find that MathWorks will remove this feature in some near future release. Until then &#8211; have fun using it!<br />
Can you find a good use for <i><b>graphics.cursorbar</b></i>? if so, please let us know by posting a comment <a href="/articles/undocumented-cursorbar-object/#respond">below</a>.<br />
<b><u>Note:</u></b> <i><b>graphics.cursorbar</b></i> was removed in Matlab release R2014b (8.4), as part of the transition to the new graphics system (HG2). Perhaps one day a replacement functionality will be added. Until then, we can use Michelle Hirsch&#8217;s <a target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/2875-dualcursor">dualcursor</a> utility, or Yaroslav Don&#8217;s direct replacement <a target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/49612-cursorbar">cursorbar</a> (see <a href="/articles/undocumented-cursorbar-object#comment-345555">comment below</a>), which apparently has the official approval of MathWorks and was selected as <a href="https://blogs.mathworks.com/pick/2017/09/08/cursorbar" rel="nofollow" target="_blank">File Exchange Pick of the Week</a>.</p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/undocumented-cursorbar-object">Undocumented cursorbar object</a> appeared first on <a rel="nofollow" href="https://undocumentedmatlab.com">Undocumented Matlab</a>.</p>
<div class='yarpp-related-rss'>
<h3>Related posts:</h3><ol>
<li><a href="https://undocumentedmatlab.com/articles/getundoc-get-undocumented-object-properties" rel="bookmark" title="getundoc &#8211; get undocumented object properties">getundoc &#8211; get undocumented object properties </a> <small>getundoc is a very simple utility that displays the hidden (undocumented) properties of a specified handle object....</small></li>
<li><a href="https://undocumentedmatlab.com/articles/handle-object-as-default-class-property-value" rel="bookmark" title="Handle object as default class property value">Handle object as default class property value </a> <small>MCOS property initialization has a documented but unexpected behavior that could cause many bugs in user code. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/accessing-private-object-properties" rel="bookmark" title="Accessing private object properties">Accessing private object properties </a> <small>Private properties of Matlab class objects can be accessed (read and write) using some undocumented techniques. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/general-use-object-copy" rel="bookmark" title="General-use object copy">General-use object copy </a> <small>Matlab's dual internal serialization/deserialization functions can be used to create duplicates of any object. ...</small></li>
</ol>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://undocumentedmatlab.com/articles/undocumented-cursorbar-object/feed</wfw:commentRss>
			<slash:comments>40</slash:comments>
		
		
			</item>
		<item>
		<title>New information on HG2</title>
		<link>https://undocumentedmatlab.com/articles/new-information-on-hg2?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=new-information-on-hg2</link>
					<comments>https://undocumentedmatlab.com/articles/new-information-on-hg2#comments</comments>
		
		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Mon, 10 May 2010 22:09:39 +0000</pubDate>
				<category><![CDATA[Figure window]]></category>
		<category><![CDATA[Handle graphics]]></category>
		<category><![CDATA[High risk of breaking in future versions]]></category>
		<category><![CDATA[Undocumented feature]]></category>
		<category><![CDATA[Undocumented function]]></category>
		<category><![CDATA[HG2]]></category>
		<category><![CDATA[Pure Matlab]]></category>
		<category><![CDATA[schema.class]]></category>
		<category><![CDATA[schema.prop]]></category>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=1473</guid>

					<description><![CDATA[<p>More information on Matlab's new HG2 object-oriented handle-graphics system</p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/new-information-on-hg2">New information on HG2</a> appeared first on <a rel="nofollow" href="https://undocumentedmatlab.com">Undocumented Matlab</a>.</p>
<div class='yarpp-related-rss'>
<h3>Related posts:</h3><ol>
<li><a href="https://undocumentedmatlab.com/articles/performance-accessing-handle-properties" rel="bookmark" title="Performance: accessing handle properties">Performance: accessing handle properties </a> <small>Handle object property access (get/set) performance can be significantly improved using dot-notation. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/creating-a-simple-udd-class" rel="bookmark" title="Creating a simple UDD class">Creating a simple UDD class </a> <small>This article explains how to create and test custom UDD packages, classes and objects...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/adding-dynamic-properties-to-graphic-handles" rel="bookmark" title="Adding dynamic properties to graphic handles">Adding dynamic properties to graphic handles </a> <small>It is easy and very useful to attach dynamic properties to Matlab graphics objects in run-time. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/draggable-plot-data-tips" rel="bookmark" title="Draggable plot data-tips">Draggable plot data-tips </a> <small>Matlab's standard plot data-tips can be customized to enable dragging, without being limitted to be adjacent to their data-point. ...</small></li>
</ol>
</div>
]]></description>
										<content:encoded><![CDATA[<p>Last week I posted a couple of articles on <a target="_blank" href="/articles/undocumented-feature-function/">the undocumented <b><i>feature</i></b> function</a> and Matlab&#8217;s apparent move towards a <a target="_blank" href="/articles/matlab-hg2/">class-based Handle-Graphics system</a> called HG2.<br />
Apparently I caused a bit of a stir&#8230;<br />
This is normally a weekly blog. But I wanted to share some additional relevant information as well as some interesting tips I received in private communications. Please note that much of the following is speculation or guesswork and may be incorrect or even entirely wacky. Please read the following with more than the usual grain of skepticism&#8230;</p>
<h3 id="UDD">UDD</h3>
<p>A bit of historical background: Matlab&#8217;s existing Handle Graphics system is based on UDD (Universal Data Dictionary) objects. Prior to Matlab Release 12 (a.k.a. 6.0) back in 2000, Matlab was written exclusively in C and HG and Simulink used differing approaches to objects in the MathWorks codebase. UDD was then added for R12 using C++ code with C wrappers for internal use by the MathWorks developers. UDD enabled a new unified approach for HG and Simulink (recall the major overhaul to the Matlab interface in that release, which also modified the GUI to be Java-based). While the HG handles remained numeric, behind the scenes they relied on the new UDD system, which remained undocumented.<br />
Matlab users who wished to leverage UDD classes could (and still can) access it via some undocumented interface functions: <i><b>handle, handle.listener, handle.event, classhandle, schema.prop, schema.class, schema.event</b></i> (and other <i><b>schema.*</b></i> functions), <i><b>findprop, findclass, findevent</b></i> and several others. Some of these functions were mentioned in past articles on this blog, and others will perhaps be explained in future articles. You can find numerous mentions and usage examples of UDD in the Matlab codebase that is part of each Matlab installation.<br />
In /toolbox/matlab/helptools/+helpUtils/@HelpProcess/getHelpText.m we can see a related feature (<i><b>feature</b></i>(&#8216;SearchUUDClassesForHelp&#8217;, flag)) which can apparently be used to allow access to the h1 line and help text for UDD methods. Unfortunately, I have not found any relevant UDD candidates for this. I would be very happy to hear if you know of any objects/methods which have a UDD help section.</p>
<h3 id="MCOS">MCOS</h3>
<p>Perhaps Matlab&#8217;s Class Object System (MCOS), <a target="_blank" rel="nofollow" href="https://www.mathworks.com/matlabcentral/newsreader/view_thread/97653#247876">first introduced in R14</a> (a.k.a. 7.0, released in 2004) grew out of the UDD beginnings, and perhaps it was developed separately. The fact is that it shared several terms and concepts (&#8220;schema&#8221;, properties meta-data, events) with UDD, although no direct interaction between UDD and MCOS exists, AFAIK.<br />
As an interesting side-note, MCOS was introduced as an opt-in beta-testing feature in R14SP2 (7.0.4, released in 2005). This beta feature cannot be found in the <a target="_blank" rel="nofollow" href="http://www.mathworks.com/access/helpdesk/help/techdoc/rn/bqsq452.html">official online version of the R14SP2 release notes</a>, but can be found in the hardcover version pages 10-11:</p>
<blockquote><p>New syntax and features for creating and working with classes in MATLAB. For R14SP2, these features are at a Beta level. If you are interested in being a Beta tester for these features, see &#8220;Beta Test the MATLAB Class System&#8221; on page 11.<br />
<strong>Beta Test the MATLAB Class System</strong>. MATLAB 7.0.4 includes a Beta version of new syntax and features for working with classes in MATLAB, which simplify and expand object-oriented programming capabilities in MATLAB. Participation in this Beta program is open only to customers who are current<br />
on their maintenance for MATLAB. Trial passcodes will not be made available for this Beta test. If you are interested in being a Beta tester for these features, register on the MathWorks Web site, at <a target="_blank" rel="nofollow" href="http://www.mathworks.com/products/beta/r14sp2/signup_newfeatures.html">http://www.mathworks.com/products/beta/r14sp2/signup_newfeatures.html</a>.</p></blockquote>
<p>(needless to say, this webpage was since removed&#8230;)<br />
The MCOS syntax has changed between releases and was not very stable, until it was formally introduced in R2008a (a.k.a. 7.6, released in 2008). You can look at /toolbox/matlab/iofun/@memmapfile/memmapfile.m to see the MCOS evolution from R14 onward.</p>
<h3 id="HG2">HG2</h3>
<p>The new HG2 appears to be a merger of MCOS and UDD, using MCOS infrastructure for UDD classes and properties, finally throwing away the old numeric handles and C wrappers for the more powerful object-oriented approach.<br />
For the transition period between HG and HG2, there seems to be a dedicated feature: <i><b>feature</b></i>(&#8216;HGtoCOS&#8217;, handle) apparently converts a UDD (&#8220;HG&#8221;) handle into an HG2 (&#8220;COS&#8221;) handle. You can also use <i><b>feature</b></i>(&#8216;HGtoCOS&#8217;, 0) to obtain an MCOS object of the desktop (=handle 0). Here is a sample result on a Matlab 2009 release:</p>
<pre lang="matlab">
>> hFig = figure
hFig =
     1
>> fmcos = feature('HGtoCOS', hFig)
fmcos =
  gbtmcos.figure handle
  Package: gbtmcos
  Properties:
                 Alphamap: [1x64 double]
             BeingDeleted: 'off'
               BusyAction: 'queue'
            ButtonDownFcn: []
                 Children: [0x1 double]
                 Clipping: 'on'
          CloseRequestFcn: 'closereq'
                    Color: [0.8000 0.8000 0.8000]
                 Colormap: [64x3 double]
                      ...  (all the regular figure properties)
</pre>
<p>Note that in that here, the new object package was called GBTMCOS &#8211; perhaps meaning a GBT version of the MCOS system. This corresponds to the <i><b>feature</b></i>(&#8216;useGBT2&#8217;) that I reported in the <a target="_blank" href="/articles/undocumented-feature-function/">features article</a>. I have absolutely no idea what GBT stands for, whether it is a synonym for HG2 or not exactly, and what the differences are between GBT1.5 and GBT2. In any case, in R2010a, the same <i><b>feature</b></i>(&#8216;HGtoCOS&#8217;, handle) code returns a ui.figure object: &#8220;GBTMCOS&#8221; was simply renamed &#8220;UI&#8221;.<br />
I do not know how to convert an HG2 back to a UDD/HG handle. None of the following appears to work:</p>
<pre lang="matlab">
>> fmcos.getdoubleimpl
ans =
    -1
>> fmcos.double
ans =
on
>> double(fmcos)
ans =
    -1
>> handle(fmcos)
??? Error using ==> handle
Cannot convert to handle.
</pre>
<p>I would love to hear any additional information on these subjects, either anonymously or on record. You can use either a direct mail (see link at the top-right of this page) or the <a href="#respond">comments section</a>.</p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/new-information-on-hg2">New information on HG2</a> appeared first on <a rel="nofollow" href="https://undocumentedmatlab.com">Undocumented Matlab</a>.</p>
<div class='yarpp-related-rss'>
<h3>Related posts:</h3><ol>
<li><a href="https://undocumentedmatlab.com/articles/performance-accessing-handle-properties" rel="bookmark" title="Performance: accessing handle properties">Performance: accessing handle properties </a> <small>Handle object property access (get/set) performance can be significantly improved using dot-notation. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/creating-a-simple-udd-class" rel="bookmark" title="Creating a simple UDD class">Creating a simple UDD class </a> <small>This article explains how to create and test custom UDD packages, classes and objects...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/adding-dynamic-properties-to-graphic-handles" rel="bookmark" title="Adding dynamic properties to graphic handles">Adding dynamic properties to graphic handles </a> <small>It is easy and very useful to attach dynamic properties to Matlab graphics objects in run-time. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/draggable-plot-data-tips" rel="bookmark" title="Draggable plot data-tips">Draggable plot data-tips </a> <small>Matlab's standard plot data-tips can be customized to enable dragging, without being limitted to be adjacent to their data-point. ...</small></li>
</ol>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://undocumentedmatlab.com/articles/new-information-on-hg2/feed</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
		<item>
		<title>uiundo &#8211; Matlab&#039;s undocumented undo/redo manager</title>
		<link>https://undocumentedmatlab.com/articles/uiundo-matlab-undocumented-undo-redo-manager?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=uiundo-matlab-undocumented-undo-redo-manager</link>
					<comments>https://undocumentedmatlab.com/articles/uiundo-matlab-undocumented-undo-redo-manager#comments</comments>
		
		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Thu, 29 Oct 2009 22:11:11 +0000</pubDate>
				<category><![CDATA[Figure window]]></category>
		<category><![CDATA[GUI]]></category>
		<category><![CDATA[High risk of breaking in future versions]]></category>
		<category><![CDATA[Stock Matlab function]]></category>
		<category><![CDATA[UI controls]]></category>
		<category><![CDATA[Undocumented feature]]></category>
		<category><![CDATA[Undocumented function]]></category>
		<category><![CDATA[Callbacks]]></category>
		<category><![CDATA[Pure Matlab]]></category>
		<category><![CDATA[schema.class]]></category>
		<category><![CDATA[Toolbar]]></category>
		<category><![CDATA[uitools]]></category>
		<category><![CDATA[uiundo]]></category>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=688</guid>

					<description><![CDATA[<p>The built-in uiundo function provides easy yet undocumented access to Matlab's powerful undo/redo functionality. This article explains its usage.</p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/uiundo-matlab-undocumented-undo-redo-manager">uiundo &#8211; Matlab&#039;s undocumented undo/redo manager</a> appeared first on <a rel="nofollow" href="https://undocumentedmatlab.com">Undocumented Matlab</a>.</p>
<div class='yarpp-related-rss'>
<h3>Related posts:</h3><ol>
<li><a href="https://undocumentedmatlab.com/articles/customizing-uiundo" rel="bookmark" title="Customizing uiundo">Customizing uiundo </a> <small>This article describes how Matlab's undocumented uiundo undo/redo manager can be customized...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/uisplittool-uitogglesplittool-callbacks" rel="bookmark" title="uisplittool &amp; uitogglesplittool callbacks">uisplittool &amp; uitogglesplittool callbacks </a> <small>Matlab's undocumented uisplittool and uitogglesplittool are powerful toolbar controls - this article explains how to customize their behavior...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/uisplittool-uitogglesplittool" rel="bookmark" title="uisplittool &amp; uitogglesplittool">uisplittool &amp; uitogglesplittool </a> <small>Matlab's undocumented uisplittool and uitogglesplittool are powerful controls that can easily be added to Matlab toolbars - this article explains how...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/undocumented-cursorbar-object" rel="bookmark" title="Undocumented cursorbar object">Undocumented cursorbar object </a> <small>Matlab's internal undocumented graphics.cursorbar object can be used to present dynamic data-tip cross-hairs...</small></li>
</ol>
</div>
]]></description>
										<content:encoded><![CDATA[<p>Whenever we have a Matlab GUI containing user-modifiable controls (edit boxes, sliders, toggle buttons etc.), we may wish to include an undo/redo feature. This would normally be a painful programming task. Luckily, there is an undocumented built-in Matlab support for this functionality via the <b><i>uiundo</i></b> function. Note that <b><i>uiundo</i></b> and its functionality is <u>not</u> Java-based but rather uses Matlab&#8217;s classes and the similarly-undocumented <b><i>schema</i></b>-based object-oriented approach.<br />
A couple of months ago, I explained <a target="_blank" href="/articles/figure-toolbar-components/">how to customize the figure toolbar</a>. In that article, I used the undocumented <b><i>uiundo</i></b> function as a target for the toolbar customization and promised to explain its functionality later. I would now like to explain <b><i>uiundo</i></b> and its usage.<br />
The <b><i>uiundo</i></b> function is basically an accessor for Matlab&#8217;s built-in undo/redo manager object. It is located in the <i>uitools</i> folder (%MATLABROOT%\toolbox\matlab\uitools) and its <i>@uiundo</i> sub-folder. To use <b><i>uiundo</i></b>, simply define within each uicontrol&#8217;s callback function (where we normally place our application GUI logic) the name of the undo/redo action, what should be done to undo the action, and what should be done if the user wished to redo the action after undoing it. <b><i>uiundo</i></b> then takes care of adding this data to the figure&#8217;s undo/redo options under Edit in the main figure menu.<br />
For example, let&#8217;s build a simple GUI consisting of a slider that controls the value of an edit box:</p>
<pre lang="matlab">
hEditbox = uicontrol('style','edit', 'position',[20,60,40,40]);
set(hEditbox, 'Enable','off', 'string','0');
hSlider = uicontrol('style','slider','userdata',hEditbox);
callbackStr = 'set(get(gcbo,''userdata''),''string'',num2str(get(gcbo,''value'')))';
set(hSlider,'Callback',callbackStr);
</pre>
<p><center><figure style="width: 284px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" alt="Simple GUI with slider update of a numeric value" src="https://undocumentedmatlab.com/images/uiundo1.png" title="Simple GUI with slider update of a numeric value" width="284" height="166" /><figcaption class="wp-caption-text">Simple GUI with slider update of a numeric value</figcaption></figure></center><br />
Now, let&#8217;s attach undo/redo actions to the slider&#8217;s callback. First, place the following in test_uiundo.m:</p>
<pre lang="matlab">
% Main callback function for slider updates
function test_uiundo(varargin)
  % Update the edit box with the new value
  hEditbox = get(gcbo,'userdata');
  newVal = get(gcbo,'value');
  set(hEditbox,'string',num2str(newVal));
  % Retrieve and update the stored previous value
  oldVal = getappdata(gcbo,'oldValue');
  if isempty(oldVal),  oldVal=0;  end
  setappdata(gcbo,'oldValue',newVal);
  % Prepare an undo/redo action
  cmd.Name = sprintf('slider update (%g to %g)',oldVal,newVal);
  % Note: the following is not enough since it only
  %       updates the slider and not the editbox...
  %cmd.Function        = @set;                  % Redo action
  %cmd.Varargin        = {gcbo,'value',newVal};
  %cmd.InverseFunction = @set;                  % Undo action
  %cmd.InverseVarargin = {gcbo,'value',oldVal};
  % This takes care of the update problem...
  cmd.Function        = @internal_update;       % Redo action
  cmd.Varargin        = {gcbo,newVal,hEditbox};
  cmd.InverseFunction = @internal_update;       % Undo action
  cmd.InverseVarargin = {gcbo,oldVal,hEditbox};
  % Register the undo/redo action with the figure
  uiundo(gcbf,'function',cmd);
end
% Internal update function to update slider & editbox
function internal_update(hSlider,newValue,hEditbox)
  set(hSlider,'value',newValue);
  set(hEditbox,'string',num2str(newValue));
end
</pre>
<p>And now let&#8217;s point the slider&#8217;s callback to our new function:</p>
<pre lang="matlab">
>> set(hSlider,'Callback',@test_uiundo);
</pre>
<p><center><figure style="width: 284px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" alt="Undo/redo functionality integrated in the figure" src="https://undocumentedmatlab.com/images/uiundo2a.png" title="Undo/redo functionality integrated in the figure" width="284" height="166" /><figcaption class="wp-caption-text">Undo/redo functionality integrated in the figure</figcaption></figure></center><br />
We can also invoke the current Undo and Redo actions programmatically, by calling <b><i>uiundo</i></b> with the &#8216;execUndo&#8217; and &#8216;execRedo&#8217; arguments:</p>
<pre lang="matlab">
uiundo(hFig,'execUndo');
uiundo(hFig,'execRedo');
</pre>
<p>When invoking the current Undo and Redo actions programmatically, we can ensure that this action would be invoked only if it is a specific action that is intended:</p>
<pre lang="matlab">
uiundo(hFig,'execUndo','Save data');  % should equal cmd.Name
</pre>
<p>We can use this approach to attach programmatic undo/redo actions to new toolbar or GUI buttons. The code for this was given in the <a target="_blank" href="/articles/figure-toolbar-components/">above-mentioned article</a>. Here is the end-result:<br />
<center><br />
<figure style="width: 382px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" alt="Undo/redo functionality integrated in the figure toolbar" src="https://undocumentedmatlab.com/images/uiundo5.png" title="Undo/redo functionality integrated in the figure toolbar" width="302" height="199" /><br />
<br />
<img loading="lazy" decoding="async" alt="Undo/redo functionality integrated in the figure toolbar" src="https://undocumentedmatlab.com/images/uiundo6.png" title="Undo/redo functionality integrated in the figure toolbar" width="382" height="221" /><figcaption class="wp-caption-text">Undo/redo functionality integrated in the figure toolbar</figcaption></figure><br />
</center><br />
In my next post, due next week, I will explore advanced customizations of this functionality.</p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/uiundo-matlab-undocumented-undo-redo-manager">uiundo &#8211; Matlab&#039;s undocumented undo/redo manager</a> appeared first on <a rel="nofollow" href="https://undocumentedmatlab.com">Undocumented Matlab</a>.</p>
<div class='yarpp-related-rss'>
<h3>Related posts:</h3><ol>
<li><a href="https://undocumentedmatlab.com/articles/customizing-uiundo" rel="bookmark" title="Customizing uiundo">Customizing uiundo </a> <small>This article describes how Matlab's undocumented uiundo undo/redo manager can be customized...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/uisplittool-uitogglesplittool-callbacks" rel="bookmark" title="uisplittool &amp; uitogglesplittool callbacks">uisplittool &amp; uitogglesplittool callbacks </a> <small>Matlab's undocumented uisplittool and uitogglesplittool are powerful toolbar controls - this article explains how to customize their behavior...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/uisplittool-uitogglesplittool" rel="bookmark" title="uisplittool &amp; uitogglesplittool">uisplittool &amp; uitogglesplittool </a> <small>Matlab's undocumented uisplittool and uitogglesplittool are powerful controls that can easily be added to Matlab toolbars - this article explains how...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/undocumented-cursorbar-object" rel="bookmark" title="Undocumented cursorbar object">Undocumented cursorbar object </a> <small>Matlab's internal undocumented graphics.cursorbar object can be used to present dynamic data-tip cross-hairs...</small></li>
</ol>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://undocumentedmatlab.com/articles/uiundo-matlab-undocumented-undo-redo-manager/feed</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
			</item>
		<item>
		<title>Displaying hidden handle properties</title>
		<link>https://undocumentedmatlab.com/articles/displaying-hidden-handle-properties?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=displaying-hidden-handle-properties</link>
					<comments>https://undocumentedmatlab.com/articles/displaying-hidden-handle-properties#comments</comments>
		
		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Tue, 05 May 2009 23:03:55 +0000</pubDate>
				<category><![CDATA[Hidden property]]></category>
		<category><![CDATA[High risk of breaking in future versions]]></category>
		<category><![CDATA[JavaFrame]]></category>
		<category><![CDATA[OuterPosition]]></category>
		<category><![CDATA[PixelBounds]]></category>
		<category><![CDATA[schema.class]]></category>
		<category><![CDATA[schema.prop]]></category>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=237</guid>

					<description><![CDATA[<p>I present two ways of checking undocumented hidden properties in Matlab Handle Graphics (HG) handles</p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/displaying-hidden-handle-properties">Displaying hidden handle properties</a> appeared first on <a rel="nofollow" href="https://undocumentedmatlab.com">Undocumented Matlab</a>.</p>
<div class='yarpp-related-rss'>
<h3>Related posts:</h3><ol>
<li><a href="https://undocumentedmatlab.com/articles/performance-accessing-handle-properties" rel="bookmark" title="Performance: accessing handle properties">Performance: accessing handle properties </a> <small>Handle object property access (get/set) performance can be significantly improved using dot-notation. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/adding-custom-properties-to-gui-objects" rel="bookmark" title="Adding custom properties to GUI objects">Adding custom properties to GUI objects </a> <small>It is very easy to add custom user-defined properties and methods to GUI handles and Java references in Matlab. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/handle-graphics-behavior" rel="bookmark" title="Handle Graphics Behavior">Handle Graphics Behavior </a> <small>HG behaviors are an important aspect of Matlab graphics that enable custom control of handle functionality. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/hidden-hg2-plot-functionality" rel="bookmark" title="Accessing hidden HG2 plot functionality">Accessing hidden HG2 plot functionality </a> <small>In HG2, some of the plot functionality is hidden in undocumented properties. ...</small></li>
</ol>
</div>
]]></description>
										<content:encoded><![CDATA[<p>Matlab Handle Graphics (HG) is a great way to manipulate GUI objects. HG handles often have some undocumented hidden properties. One pretty well-known example is the <strong>JavaFrame</strong> property of the figure handle, which enables access to the GUI&#8217;s underlying Java peer object.  We can use hidden properties just like any other handle property, using the built-in <b><i>get</i></b> and <b><i>set</i></b> functions.<br />
But how can we know about these properties? Here are two methods to do so. Like the hidden properties, these two methods are themselves undocumented&#8230;<br />
1. use the desktop&#8217;s hidden <strong>HideUndocumented</strong> property:</p>
<blockquote>
<pre><span style="color: #000000">set(0,</span><span style="color: #800080">'HideUndocumented','off'</span><span style="color: #000000">);</pre>
</blockquote>
<p>From now on, when displaying handle properties using <b><i>get</i></b> and <b><i>set</i></b> you&#8217;ll see the hidden properties.<br />
Note that some of the properties might display a warning indication:</p>
<blockquote>
<pre><span style="color: #000000">>> get(gcf)</span>
	Alphamap = [ (1 by 64) double array]
	BackingStore = on
	CloseRequestFcn = closereq
	Color = [0.8 0.8 0.8]
	Colormap = [ (64 by 3) double array]
	CurrentAxes = []
	CurrentCharacter =
	CurrentKey =
	CurrentModifier = [ (1 by 0) cell array]
	CurrentObject = []
	CurrentPoint = [0 0]
	Dithermap<span style="color: #800000">Warning: figure Dithermap is no longer useful
 with TrueColor displays, and will be removed in a future release.</span>
 = [ (64 by 3) double array]
        ...
</pre>
</blockquote>
<p>2. Access the properties&#8217; definition in the handle&#8217;s class definition:</p>
<blockquote>
<pre><span style="color: #000000">>> ch = classhandle(handle(gcf));
>> props = get(ch,</span><span style="color: #800080">'Properties'</span><span style="color: #000000">);
>> propsVisibility = get(props,</span><span style="color: #800080">'Visible'</span><span style="color: #000000">)';
>> hiddenProps = props(strcmp(propsVisibility,</span><span style="color: #800080">'off'</span><span style="color: #000000">));
>> sort(get(hiddenProps,</span><span style="color: #800080">'Name'</span><span style="color: #000000">))</span>
ans =
    'ALimInclude'
    'ActivePositionProperty'
    'ApplicationData'
    'BackingStore'
    'Behavior'
    'CLimInclude'
    'CurrentKey'
    'CurrentModifier'
    'Dithermap'
    'DithermapMode'
    'ExportTemplate'
    'HelpFcn'
    'HelpTopicKey'
    'HelpTopicMap'
    'IncludeRenderer'
    'JavaFrame'
    'OuterPosition'
    'PixelBounds'
    'PrintTemplate'
    'Serializable'
    'ShareColors'
    'UseHG2'
    'WaitStatus'
    'XLimInclude'
    'YLimInclude'
    'ZLimInclude'
</pre>
</blockquote>
<p>Different HG handles have different hidden properties. Not all these properties are useful. For example, I have found the <strong>PixelBounds</strong> property to be problematic &#8211; (it sometimes reports incorrect values!). Other properties (like <strong>Dithermap</strong> or <strong>ShareColors</strong>) are deprecated and display a warning wherever they are accessed.<br />
But every so often we find a hidden property that can be of some actual benefit. Let&#8217;s take the figure handle&#8217;s <strong>OuterPosition</strong> property for example. It provides the figure&#8217;s external position values, including the space used by the window frame, toolbars etc., whereas the regular documented <strong>Position</strong> property only reports the <b>internal</b> bounds:</p>
<blockquote>
<pre><span style="color: #000000">>> get(gcf,</span><span style="color: #800080">'pos'</span>)
ans =
   232   246   560   420
<span style="color: #000000">>> get(gcf,</span><span style="color: #800080">'outer'</span>)
ans =
   228   242   568   502
</pre>
</blockquote>
<p>In future posts I will sometimes use such hidden properties. You can find the latest list by looking at this blog&#8217;s <a href="/articles/category/Hidden-property/" target="_blank">&#8220;Hidden property&#8221;</a> category page.<br />
Note: Like the rest of Matlab&#8217;s undocumented items, all hidden properties are undocumented, unsupported and may well change in future Matlab releases so use them with care.<br />
Did you find any useful hidden property? If so, then please leave your finding in the comments section below.</p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/displaying-hidden-handle-properties">Displaying hidden handle properties</a> appeared first on <a rel="nofollow" href="https://undocumentedmatlab.com">Undocumented Matlab</a>.</p>
<div class='yarpp-related-rss'>
<h3>Related posts:</h3><ol>
<li><a href="https://undocumentedmatlab.com/articles/performance-accessing-handle-properties" rel="bookmark" title="Performance: accessing handle properties">Performance: accessing handle properties </a> <small>Handle object property access (get/set) performance can be significantly improved using dot-notation. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/adding-custom-properties-to-gui-objects" rel="bookmark" title="Adding custom properties to GUI objects">Adding custom properties to GUI objects </a> <small>It is very easy to add custom user-defined properties and methods to GUI handles and Java references in Matlab. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/handle-graphics-behavior" rel="bookmark" title="Handle Graphics Behavior">Handle Graphics Behavior </a> <small>HG behaviors are an important aspect of Matlab graphics that enable custom control of handle functionality. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/hidden-hg2-plot-functionality" rel="bookmark" title="Accessing hidden HG2 plot functionality">Accessing hidden HG2 plot functionality </a> <small>In HG2, some of the plot functionality is hidden in undocumented properties. ...</small></li>
</ol>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://undocumentedmatlab.com/articles/displaying-hidden-handle-properties/feed</wfw:commentRss>
			<slash:comments>15</slash:comments>
		
		
			</item>
	</channel>
</rss>
