MATLAB:strmatch与strcmp [英] MATLAB: strmatch vs strcmp

查看:265
本文介绍了MATLAB:strmatch与strcmp的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我使用char字符串作为指针,而使用chars的单元格数组作为haysack,则以下内容每次 都能获得相同的结果吗?我正在查看他们的文档,但没有发现其他建议.我也想向SO的社区查询.

If I'm using a char string as the needle and a cell array of chars as the haysack, would the following achieve the same results every time? I'm looking at their documentations, but I don't see anything that would suggest otherwise. I wanted to check with SO's community as well.

基本上

k = strmatch('abc', cellArray, 'exact');

k2 = find(strcmp('abc', cellArray));

其中,cellArray是char的Nx1单元数组,并且在任意索引处均具有'abc'值.例如,如果cellArray在索引10、20和30处具有abc.那么对于任何cellArray每次都为真?

where cellArray is an Nx1 cell array of chars and it has 'abc' values at arbitrary indices. For example, if cellArray has abc at indices 10, 20, and 30. Then would the following be true everytime for any cellArray?

k = [10 20 30];

k2 = [10 20 30];

此外,如果两种方法都返回相同的答案,那么在这种搜索情况下(何时在相同数据类型的单元格数组中查找char字符串),您将何时在strcmp上使用strmatch? strmatch非常慢,如果有人想知道我为什么要问.

Also, if both methods return the same answers, when would you use strmatch over strcmp in this kind of search scenario (looking for a char string in a cell array of same data type)? strmatch is extremely slow, if anyone is wondering why I'm even asking.

推荐答案

strmatch.使用strncmpvalidatestring代替. strmatch将从Matlab的未来版本中删除. *警告在Matlab 2017 a中给出.

strmatch is not recommended. Use strncmp or validatestring instead. strmatch will be removed from a future version of matlab. *Warning given in Matlab 2017 a.

这篇关于MATLAB:strmatch与strcmp的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆