contains 函数在运行相同代码时,为什么返回了不同的逻辑数组?
2 views (last 30 days)
Show older comments
a=[ "水果店" "武汉水果店" "宜昌水果店" "襄阳水果店" "荆州水果店"
"饭店" "武汉饭店" "宜昌饭店" "襄阳饭店" "荆州饭店" ];
store_name ={'宜昌水果店','武汉水果店'};
T=contains(a,store_name{1});
T
store_name ={'宜昌水果店','武汉水果店'};
T=contains(a,store_name{1});
T
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1701681/image.bmp)
0 Comments
Accepted Answer
Voss
on 22 May 2024
Edited: Voss
on 22 May 2024
There is a hidden character at the beginning of the first store_name{1}
store_name ={'宜昌水果店','武汉水果店'};
+store_name{1} % character codes
which is not in the second store_name{1}
store_name ={'宜昌水果店','武汉水果店'};
+store_name{1} % character codes
There are various ways to remove that extra character, e.g., using strrep:
store_name ={'宜昌水果店','武汉水果店'}; % 1st one again
+store_name{1} % character codes
store_name{1} = strrep(store_name{1},char(65279),'');
+store_name{1} % character codes
Now they are the same and produce the same result when checking against a.
a=[ "水果店" "武汉水果店" "宜昌水果店" "襄阳水果店" "荆州水果店"
"饭店" "武汉饭店" "宜昌饭店" "襄阳饭店" "荆州饭店" ];
store_name ={'宜昌水果店','武汉水果店'};
store_name{1} = strrep(store_name{1},char(65279),'');
T = contains(a,store_name{1})
store_name ={'宜昌水果店','武汉水果店'};
T = contains(a,store_name{1})
0 Comments
More Answers (0)
See Also
Categories
Find more on Multidimensional Arrays 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!