I originally wrote the search with nested for loops (I know, I should be shot), but then to "optimize" it, I used ismember and find to make it better. Unfortunately, it slowed it down rather significantly. I was excited to see this code, but it turn out that it does it the same way. Too bad.
A good tool, that does what it claims to do. It uses a good algorithm for the solution. It has quite clear help, with an H1 line to describe & find the function.
The only thing I would have done beyond this is add a test or so to verify the inputs. For example, what happens in this code if X is an array? In fact, if the array has the same number of columns as M, then it runs without producing an error, but perhaps the result is a surprise to the user. This behavior is definitely undocumented.
I would suggest adding a test to verify that X is a vector. If it passes that first test, then it must also conform in size with M, so a row vector must have the same number of columns as M. If it is a column vector, then it must have the same number of rows as M.
Failing these tests should return an error message that will help the user to see what they have done wrong. The best code is friendly code, that fails softly. Don't let your code return a confusing error message from ismember, or a completely unexpected result they will then have to track down as a bug in their own code.
I originally wrote the search with nested for loops (I know, I should be shot), but then to "optimize" it, I used ismember and find to make it better. Unfortunately, it slowed it down rather significantly. I was excited to see this code, but it turn out that it does it the same way. Too bad.
A good tool, that does what it claims to do. It uses a good algorithm for the solution. It has quite clear help, with an H1 line to describe & find the function.
The only thing I would have done beyond this is add a test or so to verify the inputs. For example, what happens in this code if X is an array? In fact, if the array has the same number of columns as M, then it runs without producing an error, but perhaps the result is a surprise to the user. This behavior is definitely undocumented.
I would suggest adding a test to verify that X is a vector. If it passes that first test, then it must also conform in size with M, so a row vector must have the same number of columns as M. If it is a column vector, then it must have the same number of rows as M.
Failing these tests should return an error message that will help the user to see what they have done wrong. The best code is friendly code, that fails softly. Don't let your code return a confusing error message from ismember, or a completely unexpected result they will then have to track down as a bug in their own code.
Well written in all other respects though.
Comment only