<?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>ismembc &#8211; Undocumented Matlab</title>
	<atom:link href="https://undocumentedmatlab.com/articles/tag/ismembc/feed" rel="self" type="application/rss+xml" />
	<link>https://undocumentedmatlab.com</link>
	<description>Professional Matlab consulting, development and training</description>
	<lastBuildDate>Wed, 08 Apr 2009 09:23:00 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.7.3</generator>
	<item>
		<title>ismembc &#8211; undocumented helper function</title>
		<link>https://undocumentedmatlab.com/articles/ismembc-undocumented-helper-function?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=ismembc-undocumented-helper-function</link>
					<comments>https://undocumentedmatlab.com/articles/ismembc-undocumented-helper-function#comments</comments>
		
		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Wed, 08 Apr 2009 09:23:00 +0000</pubDate>
				<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[<p>Matlab has several undocumented internal helper functions that can be useful on their own in some cases. This post presents the ismembc function.</p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/ismembc-undocumented-helper-function">ismembc &#8211; undocumented helper function</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/sprintfc-undocumented-helper-function" rel="bookmark" title="sprintfc &#8211; undocumented helper function">sprintfc &#8211; undocumented helper function </a> <small>The built-in sprintfc function can be used to quickly generate a cell-array of formatted strings. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/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="https://undocumentedmatlab.com/articles/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>
<li><a href="https://undocumentedmatlab.com/articles/datenum-performance" rel="bookmark" title="Datenum performance">Datenum performance </a> <small>The performance of the built-in Matlab function datenum can be significantly improved by using an undocumented internal help function...</small></li>
</ol>
</div>
]]></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.<br />
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.<br />
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><br />
<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.<br />
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.<br />
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>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/ismembc-undocumented-helper-function">ismembc &#8211; undocumented helper function</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/sprintfc-undocumented-helper-function" rel="bookmark" title="sprintfc &#8211; undocumented helper function">sprintfc &#8211; undocumented helper function </a> <small>The built-in sprintfc function can be used to quickly generate a cell-array of formatted strings. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/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="https://undocumentedmatlab.com/articles/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>
<li><a href="https://undocumentedmatlab.com/articles/datenum-performance" rel="bookmark" title="Datenum performance">Datenum performance </a> <small>The performance of the built-in Matlab function datenum can be significantly improved by using an undocumented internal help function...</small></li>
</ol>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://undocumentedmatlab.com/articles/ismembc-undocumented-helper-function/feed</wfw:commentRss>
			<slash:comments>14</slash:comments>
		
		
			</item>
	</channel>
</rss>
