本文介绍了是否可以在MATLAB中的表达式上应用冒号运算符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果可以在表达式上使用冒号运算符,则非常方便.据我所知,这是不可能的.例如,当我要计算两个矩阵之间的差异时,必须两行进行计算.
It's very convenient if it was possible to use colon operator on a expression. Well to my knowledge, it's not possible. For example when I want to calculate the differences between two matrices, I have to do it in two lines.
diff = (a - b);
err = sum(abs(diff(:)));
代替
diff = sum(abs((a-b)(:)));
反正周围吗?
推荐答案
您可以使用匿名帮助程序功能来避免语法限制. EG
You can get around syntax limitations with anonymous helper functions. EG
oneD = @(x)x(:);
diff = sum(abs(oneD(a-b))));
不过还是需要两行.
这篇关于是否可以在MATLAB中的表达式上应用冒号运算符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!