0

I have cell array that is as follow:

S{1} = [10,20,30,40,50];
S{2} = [10,20,40,50];
S{3} = [10,50,510];
S{4} = [10,20,70,40,60];
S{5} = [20,40];

and,i have a target vector:

T=[10,70]

i need to find rows of cell that T is subitem of those. for above example result is : 4

because T is subitems of row 4.

hojjat.mi
  • 1,414
  • 16
  • 22
  • Just swap `x` and `t` in my answer to [your previous, very similar question](https://stackoverflow.com/q/44408921/2586922) – Luis Mendo Jun 07 '17 at 12:07

1 Answers1

3

Get the count of matches for each cell against T and see which cells have a match count being equal to the number of elements in T, indicating that those cells have all elements from T. The assumption here is that we have unique elements in each of those cells.

Here's the implementation -

find(cellfun(@(x) nnz(ismember(x, T)), S) == numel(T))

Or as suggested by @Leander Moesinger we can get the matches for each element off T across all elements in each cell and then simply use all(), like so -

find(cellfun(@(x) all(ismember(T,x)),S))
Divakar
  • 218,885
  • 19
  • 262
  • 358