<?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>Undocumented Matlab &#187; ismember</title> <atom:link href="http://undocumentedmatlab.com/blog/tag/ismember/feed/" rel="self" type="application/rss+xml" /><link>http://undocumentedmatlab.com</link> <description>Charting Matlab's unsupported hidden underbelly</description> <lastBuildDate>Thu, 02 Feb 2012 00:24:18 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.1.1</generator> <item><title>ismembc &#8211; undocumented helper function</title><link>http://undocumentedmatlab.com/blog/ismembc-undocumented-helper-function/</link> <comments>http://undocumentedmatlab.com/blog/ismembc-undocumented-helper-function/#comments</comments> <pubDate>Wed, 08 Apr 2009 09:23:00 +0000</pubDate> <dc:creator>Yair Altman</dc:creator> <category><![CDATA[Medium risk of breaking in future versions]]></category> <category><![CDATA[Stock Matlab function]]></category> <category><![CDATA[Undocumented function]]></category> <category><![CDATA[ismembc]]></category> <category><![CDATA[ismember]]></category> <category><![CDATA[Performance]]></category> <category><![CDATA[Pure Matlab]]></category><guid
isPermaLink="false">http://undocumentedmatlab.com/?p=164</guid> <description><![CDATA[Matlab has several undocumented internal helper functions that can be useful on their own in some cases. This post presents the ismembc function.<pre> </pre>Related posts:<ol><li><a
href='http://undocumentedmatlab.com/blog/undocumented-feature-function/' rel='bookmark' title='Undocumented feature() function'>Undocumented feature() function</a> <small>Matlab's undocumented feature function enables access to some internal experimental features...</small></li><li><a
href='http://undocumentedmatlab.com/blog/javacomponent/' rel='bookmark' title='The javacomponent function'>The javacomponent function</a> <small>Matlab's built-in javacomponent function can be used to display Java components in Matlab application - this article details its usages and limitations...</small></li><li><a
href='http://undocumentedmatlab.com/blog/hgfeval/' rel='bookmark' title='The hgfeval function'>The hgfeval function</a> <small>The semi-documented hgfeval function can be useful for callback chaining - this article explains how...</small></li><li><a
href='http://undocumentedmatlab.com/blog/tic-toc-undocumented-option/' rel='bookmark' title='tic / toc &#8211; undocumented option'>tic / toc &#8211; undocumented option</a> <small>Matlab's built-in tic/toc functions have an undocumented option enabling multiple nested clockings...</small></li></ol><pre> </pre>]]></description> <content:encoded><![CDATA[<p>Matlab has a variety of internal helper functions which are used by the main (documented) functions. Some of these helper functions are undocumented and unsupported, but may be helpful in their own right &#8211; not just as internal support functions.</p><p>In this post I want to present Matlab&#8217;s built-in <em><strong>ismembc</strong></em> helper function. This function is used within the stock Matlab <em><strong>ismember</strong></em> and <strong><em>setxor</em></strong> functions for fast processing of the core <em><strong>ismember</strong></em> functionality in &#8220;regular&#8221; cases: arrays of sorted, non-sparse, non-NaN data in which we&#8217;re only interested in the logical membership information (not the index locations of the found members). In such cases, <em><strong>ismembc</strong></em> can be used directly, saving <em><strong>ismember</strong></em>&#8216;s sanity-checks overhead. <em><strong>ismembc</strong></em> uses the same interface (two inputs, single logical output) as <em><strong>ismember</strong></em> and can be a drop-in replacement for <em><strong>ismember</strong></em> for these &#8220;regular&#8221; cases.</p><p>The performance improvement may be significant: In a <a
rel="nofollow" href="http://blogs.mathworks.com/loren/2009/01/20/more-ways-to-find-matching-data" target="_blank">recent post</a>, MathWorks&#8217; Loren Shure presented different approaches for fast data retrieval, highlighting the <em><strong>ismember</strong></em> function. Let&#8217;s compare:</p><blockquote><pre>&gt;&gt; <span style="color: #008000;">% Initial setup</span>
&gt;&gt; <span style="color: #000000;">n=2e6; a=ceil(n*rand(n,1)); b=ceil(n*rand(n,1));</span>

&gt;&gt; <span style="color: #008000;">% Run <em><strong>ismember</strong></em> several times, to rule-out JIT compilation overheads</span>
&gt;&gt; <span style="color: #000000;">tic;ismember(a,b);toc;</span>
Elapsed time is 2.882907 seconds.
&gt;&gt; <span style="color: #000000;">tic;ismember(a,b);toc;</span>
Elapsed time is 2.818318 seconds.
&gt;&gt; <span style="color: #000000;">tic;ismember(a,b);toc;</span>
Elapsed time is 3.005967 seconds.

&gt;&gt; <span style="color: #008000;">% Now use <em><strong>ismembc</strong></em>:</span>
&gt;&gt; <span style="color: #000000;">tic;ismembc(a,b);toc;</span>
Elapsed time is 0.162108 seconds.
&gt;&gt; <span style="color: #000000;">tic;ismembc(a,b);toc;</span>
Elapsed time is 0.204108 seconds.
&gt;&gt; <span style="color: #000000;">tic;ismembc(a,b);toc;</span>
Elapsed time is 0.156963 seconds.
</em></pre></blockquote><p><em><strong>ismembc</strong></em> is actually a MEX file (%matlabroot%\toolbox\matlab\ops\ismembc.mexw32). Its source code is included in the same folder (%matlabroot%\toolbox\matlab\ops\ismembc.cpp) and is actually very readable. From the source code comments we learn that the comment in <em><strong>setxor</strong></em> about <em><strong>ismembc</strong></em> usage is misleading: that comment stated that the inputs must be real, but the source-code indicates that imaginary numbers are also accepted and that only the real-part should be sorted.</em></p><p><em><strong>ismembc</strong></em> should not be used carelessly: as noted, its inputs must be sorted non-sparse non-NaN values. In the general case we should either ensure this programmatically (as done in <em><strong>setxor</strong></em>) or use <em><strong>ismember</strong></em>, which handles this for us.</p><p>The nice thing about <em><strong>ismembc</strong></em> is that its source code (ismembc.cpp) is included, so even if future Matlab releases stop using this function, you can always mex-compile the source code and use it.</p><p>Readers interested in <em><strong>ismembc</strong></em> might also be interested in its sibling help function, <em><strong>ismembc2</strong></em>, which is also a mex file located (with source-code) in the same folder as <em><strong>ismembc</strong></em>. Whereas <em><strong>ismembc</strong></em> returns an array of logical values, <em><strong>ismembc2</strong></em> returns the index locations of the found members.</p><p><pre> </pre>Related posts:<ol><li><a
href='http://undocumentedmatlab.com/blog/undocumented-feature-function/' rel='bookmark' title='Undocumented feature() function'>Undocumented feature() function</a> <small>Matlab's undocumented feature function enables access to some internal experimental features...</small></li><li><a
href='http://undocumentedmatlab.com/blog/javacomponent/' rel='bookmark' title='The javacomponent function'>The javacomponent function</a> <small>Matlab's built-in javacomponent function can be used to display Java components in Matlab application - this article details its usages and limitations...</small></li><li><a
href='http://undocumentedmatlab.com/blog/hgfeval/' rel='bookmark' title='The hgfeval function'>The hgfeval function</a> <small>The semi-documented hgfeval function can be useful for callback chaining - this article explains how...</small></li><li><a
href='http://undocumentedmatlab.com/blog/tic-toc-undocumented-option/' rel='bookmark' title='tic / toc &#8211; undocumented option'>tic / toc &#8211; undocumented option</a> <small>Matlab's built-in tic/toc functions have an undocumented option enabling multiple nested clockings...</small></li></ol></p><pre> </pre>]]></content:encoded> <wfw:commentRss>http://undocumentedmatlab.com/blog/ismembc-undocumented-helper-function/feed/</wfw:commentRss> <slash:comments>5</slash:comments> </item> </channel> </rss>

<!-- W3 Total Cache: Minify debug info:
Engine:             disk: basic
Theme:              b7666
Template:           tag
-->
<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Served from: undocumentedmatlab.com @ 2012-02-04 03:20:06 -->

<!-- W3 Total Cache: Page cache debug info:
Engine:             disk: enhanced
Cache key:          blog/tag/ismember/feed/_index.xml_gzip
Caching:            enabled
Status:             not cached
Creation Time:      0.873s
Header info:
X-Pingback:         http://undocumentedmatlab.com/blog/xmlrpc.php
Set-Cookie:         wpgb_visit_last_php-default=1328350805; expires=Sun, 03-Feb-2013 10:20:05 GMT; path=/
Content-Type:       text/xml; charset=UTF-8
Last-Modified:      Sat, 04 Feb 2012 10:20:06 GMT
Vary:               Accept-Encoding, Cookie
Expires:            Sat, 04 Feb 2012 11:20:06 GMT
Pragma:             public
Cache-Control:      public, must-revalidate, proxy-revalidate
Etag:               20a57f256a830b498a25cb961575ed37
Content-Encoding:   gzip
-->
