Hints or tips when vectorizing ismember.

1 view (last 30 days)
Ale Kaszynski
Ale Kaszynski on 21 Apr 2013
For matrix A, I would like to output all the values of each row where a unique value of A occurs without using a loop, excluding the unique value being tested.
For example
A= [1,2,3,4,5,6,7,8; 1,3,4,5,6,8,9,10; 8,10,13,14,18,20,21,22]
would produce...
C{1}=[2,3,4,5,6,7,8,9,10]; C{2}=[1,3,4,5,6,7,8]; C{3}=[1,2,4,5,6,7,8,9,10]; C{4}=[1,3,4,5,6,8,9,10]; ... C{8}=[1,2,3,4,5,6,7,9,10,13,14,18,20,21,22]; and so on...
Thanks in advance for any help!
  1 Comment
Daniel Shub
Daniel Shub on 21 Apr 2013
It is not clear what the algorithm is supposed to do. I seem no relationship between your A double matrix and your C cell array. Finally, why do you want to avoid loops? Wouldn't it be better to ask for efficient code that is easy to understand and maintain? Given you don't have a working algorithm yet asking for efficient code seems like a case of premature optimization.

Sign in to comment.

Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!