<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	
	>
<channel>
	<title>
	Comments on: uicontextmenu performance	</title>
	<atom:link href="https://undocumentedmatlab.com/articles/uicontextmenu-performance/feed" rel="self" type="application/rss+xml" />
	<link>https://undocumentedmatlab.com/articles/uicontextmenu-performance?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=uicontextmenu-performance</link>
	<description>Professional Matlab consulting, development and training</description>
	<lastBuildDate>Fri, 18 Oct 2019 15:40:16 +0000</lastBuildDate>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.7.2</generator>
	<item>
		<title>
		By: E Zapato		</title>
		<link>https://undocumentedmatlab.com/articles/uicontextmenu-performance#comment-503986</link>

		<dc:creator><![CDATA[E Zapato]]></dc:creator>
		<pubDate>Fri, 18 Oct 2019 15:40:16 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=4751#comment-503986</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://undocumentedmatlab.com/articles/uicontextmenu-performance#comment-354507&quot;&gt;Niko&lt;/a&gt;.

Niko,

I know this was years ago and you&#039;ve almost certainly resolved this, but you can get the calling object via the figure&#039;s CurrentObject property. So from the callback:
&lt;pre lang=&quot;matlab&quot;&gt;get(ancestor(src, &#039;figure&#039;), &#039;CurrentObject&#039;)&lt;/pre&gt;

This answer really came from MVP Jan:
&lt;a href=&quot;https://www.mathworks.com/matlabcentral/answers/67685-how-do-i-find-out-which-uicontrol-launched-my-context-menu&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;https://www.mathworks.com/matlabcentral/answers/67685-how-do-i-find-out-which-uicontrol-launched-my-context-menu&lt;/a&gt;]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://undocumentedmatlab.com/articles/uicontextmenu-performance#comment-354507">Niko</a>.</p>
<p>Niko,</p>
<p>I know this was years ago and you&#8217;ve almost certainly resolved this, but you can get the calling object via the figure&#8217;s CurrentObject property. So from the callback:</p>
<pre lang="matlab">get(ancestor(src, 'figure'), 'CurrentObject')</pre>
<p>This answer really came from MVP Jan:<br />
<a href="https://www.mathworks.com/matlabcentral/answers/67685-how-do-i-find-out-which-uicontrol-launched-my-context-menu" target="_blank" rel="nofollow">https://www.mathworks.com/matlabcentral/answers/67685-how-do-i-find-out-which-uicontrol-launched-my-context-menu</a></p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Niko		</title>
		<link>https://undocumentedmatlab.com/articles/uicontextmenu-performance#comment-354507</link>

		<dc:creator><![CDATA[Niko]]></dc:creator>
		<pubDate>Tue, 04 Aug 2015 18:53:42 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=4751#comment-354507</guid>

					<description><![CDATA[Hi Yair,

Is it possible to have multiple objects share the same uicontextmenu? I&#039;ve tried it but the problem is I don&#039;t know how to figure out which object is right-clicked on (the callback only contains the context menu object itself)... is there some sort of (possibly java-based) workaround or do you have to use a separate uicontextmenu for each object and label it somehow? Thanks!

Niko]]></description>
			<content:encoded><![CDATA[<p>Hi Yair,</p>
<p>Is it possible to have multiple objects share the same uicontextmenu? I&#8217;ve tried it but the problem is I don&#8217;t know how to figure out which object is right-clicked on (the callback only contains the context menu object itself)&#8230; is there some sort of (possibly java-based) workaround or do you have to use a separate uicontextmenu for each object and label it somehow? Thanks!</p>
<p>Niko</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Robert Cumming		</title>
		<link>https://undocumentedmatlab.com/articles/uicontextmenu-performance#comment-322180</link>

		<dc:creator><![CDATA[Robert Cumming]]></dc:creator>
		<pubDate>Thu, 10 Apr 2014 14:44:53 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=4751#comment-322180</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://undocumentedmatlab.com/articles/uicontextmenu-performance#comment-322106&quot;&gt;Yaroslav&lt;/a&gt;.

Yaroslav,

Thank you for your comment - and indeed you are correct the solution above is a bit of a &quot;sledge hammer&quot; approach.

The point you make was &lt;i&gt;(supposed to be anyway...)&lt;/i&gt; covered in point 2 of the conclusions - you need to take care and only delete the appropriate uicontextmenus.

Your solution is a good improvement for the reader of this blog! :)   And a reminder to me to explain in more detail in the future!

Regards]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://undocumentedmatlab.com/articles/uicontextmenu-performance#comment-322106">Yaroslav</a>.</p>
<p>Yaroslav,</p>
<p>Thank you for your comment &#8211; and indeed you are correct the solution above is a bit of a &#8220;sledge hammer&#8221; approach.</p>
<p>The point you make was <i>(supposed to be anyway&#8230;)</i> covered in point 2 of the conclusions &#8211; you need to take care and only delete the appropriate uicontextmenus.</p>
<p>Your solution is a good improvement for the reader of this blog! 🙂   And a reminder to me to explain in more detail in the future!</p>
<p>Regards</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Yaroslav		</title>
		<link>https://undocumentedmatlab.com/articles/uicontextmenu-performance#comment-322106</link>

		<dc:creator><![CDATA[Yaroslav]]></dc:creator>
		<pubDate>Wed, 09 Apr 2014 19:31:05 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=4751#comment-322106</guid>

					<description><![CDATA[Robert,

It is always a great deal of vexation, when some GUI components (UI-context-menus) are not associated to their natural object (plot/axes/etc.), which leads to confusion, and sometimes, as you have shown, to a significant slowdown; thank you for pointing that out for context menus.  Yet I believe that your solution is incorrect in this case. 

The reason is very simple: when you delete the context menus with 
&lt;pre lang=&quot;matlab&quot;&gt;delete ( findobj ( h.main, &#039;type&#039;,&#039;uicontextmenu&#039; ) )&lt;/pre&gt;
you remove &lt;i&gt;all&lt;/i&gt; the associated handles inside the figure; that may pose a significant problem if you have &lt;i&gt;several&lt;/i&gt; axes with context-menus in the figure.  Using listeners will not solve the issue (unless you use a different &lt;code&gt;XObjectDeletedEvent&lt;/code&gt; for each axis), and may introduce additional peculiarities, since Matlab&#039;s event-driving mechanism flushes the graphics in its own time (see &lt;a href=&quot;http://www.mathworks.com/help/matlab/ref/drawnow.html&quot; rel=&quot;nofollow&quot;&gt;drawnow&lt;/a&gt; for more details).

What I suggest, is using Matlab&#039;s own &lt;code&gt;DeleteFcn&lt;/code&gt; mechanism.  More specifically, since the plot handles have both &lt;code&gt;DeleteFcn&lt;/code&gt; and the &lt;i&gt;linked&lt;/i&gt; &lt;code&gt;UIContextMenu&lt;/code&gt; handle, we may use it together to obtain &#8212;
&lt;pre lang=&quot;matlab&quot;&gt;plot ( h.ax, x(ii), y(ii), &#039;rs&#039;, &#039;uicontextmenu&#039;,uim , &#039;DeleteFcn&#039;,@(obj,~)delete(get(obj,&#039;UIContextMenu&#039;))); &lt;/pre&gt; 
so that when the plot is deleted, the associated &lt;code&gt;UIContextMenu&lt;/code&gt; is removed as well. On my laptop it has shown the same improvement in runtime as in your example of deleting all the context-menus in the figure whilst retaining the linkage between the plot and the menu.]]></description>
			<content:encoded><![CDATA[<p>Robert,</p>
<p>It is always a great deal of vexation, when some GUI components (UI-context-menus) are not associated to their natural object (plot/axes/etc.), which leads to confusion, and sometimes, as you have shown, to a significant slowdown; thank you for pointing that out for context menus.  Yet I believe that your solution is incorrect in this case. </p>
<p>The reason is very simple: when you delete the context menus with </p>
<pre lang="matlab">delete ( findobj ( h.main, 'type','uicontextmenu' ) )</pre>
<p>you remove <i>all</i> the associated handles inside the figure; that may pose a significant problem if you have <i>several</i> axes with context-menus in the figure.  Using listeners will not solve the issue (unless you use a different <code>XObjectDeletedEvent</code> for each axis), and may introduce additional peculiarities, since Matlab&#8217;s event-driving mechanism flushes the graphics in its own time (see <a href="http://www.mathworks.com/help/matlab/ref/drawnow.html" rel="nofollow">drawnow</a> for more details).</p>
<p>What I suggest, is using Matlab&#8217;s own <code>DeleteFcn</code> mechanism.  More specifically, since the plot handles have both <code>DeleteFcn</code> and the <i>linked</i> <code>UIContextMenu</code> handle, we may use it together to obtain &mdash;</p>
<pre lang="matlab">plot ( h.ax, x(ii), y(ii), 'rs', 'uicontextmenu',uim , 'DeleteFcn',@(obj,~)delete(get(obj,'UIContextMenu'))); </pre>
<p>so that when the plot is deleted, the associated <code>UIContextMenu</code> is removed as well. On my laptop it has shown the same improvement in runtime as in your example of deleting all the context-menus in the figure whilst retaining the linkage between the plot and the menu.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Robert Cumming		</title>
		<link>https://undocumentedmatlab.com/articles/uicontextmenu-performance#comment-321421</link>

		<dc:creator><![CDATA[Robert Cumming]]></dc:creator>
		<pubDate>Thu, 03 Apr 2014 16:12:41 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=4751#comment-321421</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://undocumentedmatlab.com/articles/uicontextmenu-performance#comment-321416&quot;&gt;sebastian&lt;/a&gt;.

Sebastian - thanks for your comments.

Indeed you are correct - its always best to be smart :)

The example above is trivialising what was a very complex GUI with many individual and customisable uicontextmenus - even the &quot;real world&quot; example I quoted was not what was really done, but trying to provide some generalised numbers on how many objects can be created if you don&#039;t take care.

The scenario I was showing here was to highlight that you should clean up uicontextmenus once they are no longer required/accessible (true for other objects too).

In both of your cases you would still need to clean up the uicontextmenu handle(s) after they have been used/no longer accessible, as the more objects you have the slower anything that uses findobj would become for example.]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://undocumentedmatlab.com/articles/uicontextmenu-performance#comment-321416">sebastian</a>.</p>
<p>Sebastian &#8211; thanks for your comments.</p>
<p>Indeed you are correct &#8211; its always best to be smart 🙂</p>
<p>The example above is trivialising what was a very complex GUI with many individual and customisable uicontextmenus &#8211; even the &#8220;real world&#8221; example I quoted was not what was really done, but trying to provide some generalised numbers on how many objects can be created if you don&#8217;t take care.</p>
<p>The scenario I was showing here was to highlight that you should clean up uicontextmenus once they are no longer required/accessible (true for other objects too).</p>
<p>In both of your cases you would still need to clean up the uicontextmenu handle(s) after they have been used/no longer accessible, as the more objects you have the slower anything that uses findobj would become for example.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: sebastian		</title>
		<link>https://undocumentedmatlab.com/articles/uicontextmenu-performance#comment-321416</link>

		<dc:creator><![CDATA[sebastian]]></dc:creator>
		<pubDate>Thu, 03 Apr 2014 15:34:53 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=4751#comment-321416</guid>

					<description><![CDATA[Instead of creating hundreds of uicontextmenu which are pretty identical, I think you/one should rather make a single, but &lt;b&gt;smart&lt;/b&gt; uicontextmenu.
You most certainly won&#039;t have hundreds of different &quot;handmade&quot; uicontextmenus.
&lt;pre&gt;
&lt;/pre&gt;
I&#039;m pretty sure in most of such cases one can either
a) make the callbacks of the individual uimenu-entries dynamic, e.g. to act on the just clicked handle
or 
b) make the uicontextmenu itself dynamic, by implementing an on-the-fly creation of its menus using the &#039;Callback&#039; of the uicontextmenu.
&lt;pre&gt;
&lt;/pre&gt;
E.g. in your example you could add the &#039;X=...&#039; and &#039;Y=...&#039; in the very beginning and simply change their labels according to which object was clicked by the user.]]></description>
			<content:encoded><![CDATA[<p>Instead of creating hundreds of uicontextmenu which are pretty identical, I think you/one should rather make a single, but <b>smart</b> uicontextmenu.<br />
You most certainly won&#8217;t have hundreds of different &#8220;handmade&#8221; uicontextmenus.</p>
<pre>
</pre>
<p>I&#8217;m pretty sure in most of such cases one can either<br />
a) make the callbacks of the individual uimenu-entries dynamic, e.g. to act on the just clicked handle<br />
or<br />
b) make the uicontextmenu itself dynamic, by implementing an on-the-fly creation of its menus using the &#8216;Callback&#8217; of the uicontextmenu.</p>
<pre>
</pre>
<p>E.g. in your example you could add the &#8216;X=&#8230;&#8217; and &#8216;Y=&#8230;&#8217; in the very beginning and simply change their labels according to which object was clicked by the user.</p>
]]></content:encoded>
		
			</item>
	</channel>
</rss>
