任何方式来完成i ++在matlab中? [英] Any way to accomplish i++ in matlab?

查看:756
本文介绍了任何方式来完成i ++在matlab中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设 srcHoughMatrix 是一个三维矩阵:



而不是

  if(currentRadius> = MINIMUM_ALLOWED_RADIUS)
%我们只使用6或以上的半径
currentHough = srcHoughMatrix ,jindex,currentRadius);
srcHoughMatrix(index,jindex,currentRadius)= currentHough + 1;
end

如何添加 1 或不使用

  srcHoughMatrix(index, jindex,currentRadius)= srcHoughMatrix(index,jindex,currentRadius)+ 1; 

感谢

解决方案

不是我不会做什么@Jonas建议,但如何使用 operator ?它用于定义新的用户定义的运算符符号或删除它们(您将需要符号工具箱)。



运算符(symb,f,T,prio)定义一个新的运算符符号 symb具有优先级 prio 的类型 T (Prefix | Postfix | Binary | Nary)的函数 f 使用new运算符计算表达式。



给定运算符++评估函数 f ,根据运算符的类型,解析器将构建以下表达式,其中:



前缀:输入x +结果

:输入x ++ y ++ z会导致f(x,y),f(x) z)。



Nary :输入x ++ y ++ z会产生f(x,y,z) p>

请参阅matlab的文档。 / p>

Assuming that srcHoughMatrix is a 3-dimensional matrix :

Instead of

    if (currentRadius >= MINIMUM_ALLOWED_RADIUS )
    % we're using only radiuses that are 6 or above 
        currentHough = srcHoughMatrix(index,jindex,currentRadius);
        srcHoughMatrix(index,jindex,currentRadius) = currentHough + 1;
    end

How can I add 1 to each cell if the condition is true , without using a temporary variable or without

srcHoughMatrix(index,jindex,currentRadius)  = srcHoughMatrix(index,jindex,currentRadius)  + 1;

Thanks

解决方案

Not that I wouldn't do what @Jonas suggested, but what about using operator ? it is used to define new user-defined operator symbols or to delete them (you will need the symbolic toolbox though).

operator(symb, f, T, prio) defines a new operator symbol symb of type T (Prefix | Postfix | Binary | Nary) with priority prio. The function f evaluates expressions using the new operator.

Given the operator symbol "++", say, with evaluating function f, the following expressions are built by the parser, depending on the type of the operator, where :

Prefix: The input ++x results in f(x).

Postfix: The input x++ results in f(x).

Binary: The input x ++ y ++ z results in f(f(x, y), z).

Nary: The input x ++ y ++ z results in f(x, y, z)).

see more at matlab's documentation.

这篇关于任何方式来完成i ++在matlab中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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