Find the intersection of a vector and cell array in MATLAB -
i have vector, allow as=[1 3 4]
, have 30 30
cell array. want check if elements of vector as
intersect elements of each cell or not? if so, want find indices of cell.
assuming cellarr
input cell array, see if approach works -
%// find intersecting elements each cell int_idx = cellfun(@(x) intersect(x,as),cellarr,'uniformoutput', false) %// find non empty cells denote intersecting cells. %// then, find row , column indices [row_ind,col_ind] = find(~cellfun('isempty',int_idx))
another approach ismember
find matches among each cell , if there any
match within cell, find indices of -
[row_ind,col_ind] =find(cell2mat(cellfun(@(x) any(ismember(x,as)),cellarr,'un', 0)))
and -
%// vertically concatenate numeric array cells vertcat_cells = vertcat(cellarr{:}) %// matches matches = any(any(bsxfun(@eq,vertcat_cells,permute(as,[1 3 2])),2),3) %// reshape matches size of cellarr , indices of matches [row_ind,col_ind] = find(reshape(matches,size(cellarr)))
matlab cell-array
No comments:
Post a Comment