Comparing two string columns
6 次查看(过去 30 天)
显示 更早的评论
I am trying to compare two string columns (of different dimensions) and I have typed in a code for that which is not working to my expectation. Any help would be highly appreciated!
So I have two string columns A (nx1) and B (mx1). After declaring these columns in my code,the conditions go like this:
for g = 1:length(A)
for h = 1:length(B)
if A(g) == B(h)
disp("%s %s\n",A(g),B(h));
end
end
end
When I ran this code, I got no matches. However, I know that there is at least 1 match (as I have seen the same strings in both the columns). So, any useful suggestions would be very helpful. Thank you in advance for your help!
1 个评论
Walter Roberson
2017-12-19
编辑:Walter Roberson
2017-12-19
When you say "string", do you mean character vectors and cell array of character vectors, or do you mean the R2016b and later string object ?
回答(2 个)
Bongane Radebe
2020-3-31
Please help I'm trying to use string comparison to compare elements of the 2 strings and actually store the common in a variable, how do i go about it?
1 个评论
Walter Roberson
2020-4-1
C = intersect(A, B)
A and B can be string arrays or cell arrays of character vectors.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Characters and Strings 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!