MATLAB 字符串比较:查找字符串在数组中的位置
在MATLAB中,可以使用strcmp()函数来比较字符串和字符串数组,并返回相同字符串的位置。\n\n下面是一个示例代码:\n\nmatlab\nstr = 'hello';\nstrArray = {'world', 'hello', 'matlab', 'hello'};\n\n% 查找与字符串相同的字符串在字符串数组中的位置\nindices = find(strcmp(str, strArray));\n\ndisp(indices);\n\n\n输出结果为:\n\n\n2\n4\n\n\n说明字符串'hello'在字符串数组strArray中的位置分别为2和4。
原文地址: https://www.cveoy.top/t/topic/pJMm 著作权归作者所有。请勿转载和采集!