Compare two strings and count the same words
2 views (last 30 days)
Hi @ all,
I have two strings. The first one are measurement results which looks like this:
iwant="Gruppe 1; Gruppe 2; Gruppe 3; Gruppe 3; ; Gruppe 6"
The second string are an overview about all groups we could find. It looks like this:
Vergleichsstring_RL="Gruppe 1; Gruppe 2; Gruppe 3; Gruppe 4; Gruppe 5; Gruppe 6; Gruppe 7" ...
So in the end I want to compare these strings and count how many of each "Gruppe" were found. The difficulty is that not all points are called Gruppe. If there is now result for e.g. Gruppe 5, there should be a zero written.
I tried it like below. It doesn't work. I import several measurement files and it seems that in this step something goes wrong:
idx = strfind(iwant(:,2), Vergleichsstring_RL);
idx = find(not(cellfun('isempty', idx)));
I appreciate every help :-) Thank you a lot
Stephen23 on 19 Jul 2022
Edited: Stephen23 on 19 Jul 2022
want = "Gruppe 1; Gruppe 2; Gruppe 3; Gruppe 3; ; Gruppe 6";
vgls = "Gruppe 1; Gruppe 2; Gruppe 3; Gruppe 4; Gruppe 5; Gruppe 6; Gruppe 7";
wc = regexp(want,'\w+\s+\d+','match')
vc = regexp(vgls,'\w+\s+\d+','match')
[ix,iy] = ismember(wc,vc)
cn = hist(iy,1:numel(vc))