Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
replace ismember with ismembc

Subject: replace ismember with ismembc

From: Dave Brackett

Date: 4 Aug, 2009 14:18:20

Message: 1 of 2

Hi, i'm trying to replace 'ismember' with 'ismembc' to speed up the operation (as mentioned here
http://undocumentedmatlab.com/blog/tag/ismember/) . However, I used 'ismember' with the 'rows' argument specified and can't see how to replicate this using 'ismembc'. Does someone know how to do this please?

Subject: replace ismember with ismembc

From: Yair Altman

Date: 4 Aug, 2009 19:09:02

Message: 2 of 2

"Dave Brackett" <davebrackett@hotmail.com> wrote in message <h59fvc$dqn$1@fred.mathworks.com>...
> Hi, i'm trying to replace 'ismember' with 'ismembc' to speed up the operation (as mentioned here
> http://undocumentedmatlab.com/blog/tag/ismember/) . However, I used 'ismember' with the 'rows' argument specified and can't see how to replicate this using 'ismembc'. Does someone know how to do this please?


Look inside the ismember code (type 'edit ismember' in the Matlab Command Window) and see that it pre-processes the data rows, before recursively re-invoking the regular ismember() function (which in turn uses ismembc).

If you're certain about all the conditioned I mentioned in the post that you linked above (i.e., only sorted non-sparse non-NaN values), then you can simply take the relevant code segment from the ismember.m code (the section after the else 'rows') and replace the recursive call to ismember() with a call to ismembc(). You can use Matlab's built-in profiler to see a code-coverage of ismember.m, showing you which lines got executed for your specific inputs - these are the lines you should copy.

I reiterate my warning - unless you're positive about the well-behavior of the input data, better stick with Matlab's ismember(), which handles edge cases and does several sanity checks. A run-time failure due to a mis-behaving data point may not be worth the performance boost of using ismembc.

Yair Altman
http://UndocumentedMatlab.com
 

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us