我有两个单元格,第一列是字符串.我目前正在使用ismember匹配两个单元格中的第一列元素.但是成员是区分大小写的.我不能使用strcmpi,因为单元格大小不等.你能建议另一种方法吗?
cell1 = { 'AAPL' [2001] ; 'GOOG' [1999] ; 'MSFT' [2010] } ;
cell2 = { 'AMZN' [2009] ; 'HP' [2011] ; 'CSC' [2005] ; 'Goog' [2010] } ;
Run Code Online (Sandbox Code Playgroud)
不区分大小写的方法:
tf = ismember(cell1(:,1), cell2(:,1)) ; % tf should be now [0; 1; 0]
Run Code Online (Sandbox Code Playgroud)
谢谢!
函数lower和upper操作字符串的单元格数组,因此您可以在调用之前使用它们将字符串转换为所有小写或大写ismember:
>> tf = ismember(lower(cell1(:, 1)), lower(cell2(:, 1)))
tf =
0
1 % <-- there's the 1 you want!
0
Run Code Online (Sandbox Code Playgroud)