Find array elements inside another array while incrementing counter
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
for kk = 1:n
str = ['<p id=',num2str(kk),'>'];
idx_s = find(strcmp(C,str));
if ~isempty(idx_s)
idx_e = idx2(find(idx2>idx_s,1));
Doc=C(idx_s:idx_e); %May need to remove tags later
Doc = regexp(Doc,'[a-z0-9\-]+','match');
Doc = [Doc{:}];
Unique_Doc_count = arrayfun(@(x) nnz(strcmp(x,Doc)), Unique);
Unique_Doc_freq=[Unique;Unique_Doc_count];
end
end
I want to search if the elements in string array 'Unique' exist in 'Doc'. I got results in 'Unique_Doc_count' as the number of their occurrences but I need just 1 or 0 values (exist) or (not exist). The aim is to loop 'kk' over multiple documents and find the number of documents that contain each word in 'Unique'. Not even number of times the word occurs, but number of documents it appears in.
2 Kommentare
per isakson
am 7 Nov. 2017
A tiny example would make it easier to help, i.e values of
n, C, Unique, idx2, ...
btw: the name Unique is dubious; it's too close to the function name unique
Antworten (0)
Siehe auch
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!