清理字符串以在Matlab中进行比较 [英] Sanitize string for comparison in Matlab
问题描述
This is a follow-up question from this that considered evalc
, instead of figgling with file-descriptors manually. You can see below an example about poor sanitization. I want to remove things such as trailing characters, all whitespaces, all newlines etc -- that usually cause unexpected things -- is there a ready sanitization command to do this?
EDU>> a
a =
1 +1*{x} -1*{y}*{z}
EDU>> b
b =
1 +1*{x} -1*{y}*{z}
EDU>> isequal(a,b)
ans =
0
推荐答案
我不知道是否存在任何现成的健壮实现,但是效果很好
I don't know whether there exist any ready robust implementation but this works pretty well
xx=@(x)regexprep(x,'\s',''); isequal(xx(a),xx(b))
我在其中使用匿名功能并删除了一些奇怪的地方,例如通常在窗口上很难看到的尾随空格/换行符.
where I use anonymous function and remove some oddities such as trailing whitespaces/newlines often hard to see on the window.
此外,strtrim()
和deblank()
之类的命令对于删除尾随字符也很有用.
Also, the commands such as strtrim()
and deblank()
can be useful to you in removing trailing characters.
这篇关于清理字符串以在Matlab中进行比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!