Remove cell that contains strings of another cell array
Show older comments
Input:
a={'Time12:30','Time12:40','Time1:40', 'Time2:40'};
b={'12:', '1:'};
Wanted Output: (delete from "a" all cells containing string listed in "b")
a={'Time2:40'}
I have tried:
for k = 1 : length(a)
for kk = 1 : length(b)
if any(~ismember(b{kk}, a{k}))
a(k) = [];
break;
end
end
end
However this gives me error of such:
Index exceeds matrix dimensions.
I am confused by the error and any guidance is appreciated! Thank you for reading my post.
Accepted Answer
More Answers (2)
Stalin Samuel
on 8 Aug 2016
0 votes
strfind(a, b(kk))%find a string from string array
Sean Mahnken
on 28 Mar 2019
You should be able to just do the k loop backwards:
for k = length(a):-1:1
for kk = 1 : length(b)
if any(~ismember(b{kk}, a{k}))
a(k) = [];
break;
end
end
end
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!