gpt4 book ai didi

matlab - 不区分大小写 'ismember' 在 MATLAB 中使用

转载 作者:行者123 更新时间:2023-12-02 08:54:38 24 4
gpt4 key购买 nike

我有两个单元格,第一列作为字符串。我目前正在使用 ismember 来匹配两个单元格中的第一列元素。但 ismember 区分大小写。我无法使用 strcmpi 因为单元格大小不等。您能建议另一种方法吗?

cell1 = { 'AAPL' [2001] ; 'GOOG' [1999] ; 'MSFT' [2010] } ; 

cell2 = { 'AMZN' [2009] ; 'HP' [2011] ; 'CSC' [2005] ; 'Goog' [2010] } ;

不区分大小写的方法:

tf = ismember(cell1(:,1), cell2(:,1)) ; % tf should be now [0; 1; 0]

谢谢!

最佳答案

功能lowerupper对字符串元胞数组进行操作,因此您可以在调用 ismember 之前使用它们将字符串转换为全部小写或大写:

>> tf = ismember(lower(cell1(:, 1)), lower(cell2(:, 1)))

tf =

0
1 % <-- there's the 1 you want!
0

关于matlab - 不区分大小写 'ismember' 在 MATLAB 中使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5872387/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com