applying difference set operation in matlab? -


i have 23 sentences have extracted text file , 6 frequent words extracted same text file. have implemented logic shows word occured in sentence word occured other set of frequent words in sentences following code , out put illustrates logic:

occurstogether = cell(length(out1)); ii=1:length(out1) jj=ii+1:length(out1) occurstogether{ii,jj} = intersect(out1{ii},out1{jj}); end end celldisp(occurstogether) 

out1 1d array shows words , in sentences occur number wise have applied setdiff inplace of intersect didn't result needed. sentences stored in sentence variable shown bellow:

sentences = regexp(f,'\s.*?[\.\!\?]','match') char(sentences) 

following occurstogether shows me 1st word occurs self in sentence number 5, 1st word occurs 2nd word in sentence 5 , 6 , on..:

occurstogether{1,1} = 5 occurstogether{1,2} = 5 6 occurstogether{1,3} = 6 9 20 , on.... 

what want find out these words don't occur follows:

notogether{1,1} = 1 2 3 4 6 7,...23 notogether{1,2} = 1 2 3 4 7,...23 notogether{1,3} = 1 2 3 4 5 7 8 10...22 

remember these 1,2,3,..23 number of sentences in pair of words occur , don't occur output shows empty {}

try this:

occurstogether{1,1} = [5]; occurstogether{1,2} = [5 6]; occurstogether{1,3} = [6 9 20]; n = 23;  result = cellfun(@(x) setdiff(1:n, x), occurstogether, 'uniformoutput', 0); 

each cell of result contain sorted vector no repetitions, per setdiff's documentation. if want change behaviour see setdiff's options.


Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

Simple Angular 2 project fails 'Unexpected reserved word' -

ios - Possible to get UIButton sizeThatFits to work? -