Comparing Two String Arrays
显示 更早的评论
Hello,
I am trying to compare two string arrays to each other to see if any of the elements in one string array are in the other string array. I assumed the best approach was to use "any" and "strcmp".
This is my code. I was able to make it work if i placed "dad" as the first elment in 'stringMe'. However when I set the first element in stringMe to "mom", it did not work. Any suggestions or advice are greatly appreciated.
string = ["dad" "hey" "mom"];
stringMe= ["mom" "bob" "ted"];
if any(strcmp(string,stringMe))
disp('hello');
end
采纳的回答
更多回答(1 个)
David Hill
2019-11-19
if sum(ismember(string,stringMe))>0
disp('hello');
end
1 个评论
Sean de Wolski
2019-11-19
if nnz()
instead of sum>0
类别
在 帮助中心 和 File Exchange 中查找有关 Cell Arrays 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!