I have a vector, let say as=[1 3 4] and I have 30 by 30 cell array. I want to check if the elements of vector as intersect with the elements of each cell or not? If so, I want to find the indices of the cell.
1
votes
1 Answers
1
votes
Assuming cellarr to be input cell array, see if this approach works for you -
%// Find intersecting elements for each cell
int_idx = cellfun(@(x) intersect(x,as),cellarr,'UniformOutput', false)
%// Find non empty cells that denote intersecting cells.
%// Then, find their row and column indices
[row_ind,col_ind] = find(~cellfun('isempty',int_idx))
Another approach with ismember to find matches among each cell and if there is any match within a cell, find the indices of it -
[row_ind,col_ind] =find(cell2mat(cellfun(@(x) any(ismember(x,as)),cellarr,'un', 0)))
And another -
%// Vertically concatenate all numeric array from cells
vertcat_cells = vertcat(cellarr{:})
%// Get all good matches
matches = any(any(bsxfun(@eq,vertcat_cells,permute(as,[1 3 2])),2),3)
%// Reshape matches into the size of cellarr and get indices of matches
[row_ind,col_ind] = find(reshape(matches,size(cellarr)))
1 x 3numeric array? - Divakarintersect, don't you mean beingequalinstead? Or else how would you defineintersect? - Divakar