Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Any way to accomplish i++ in matlab?

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

like image 645
JAN Avatar asked Jan 08 '13 21:01

JAN


People also ask

What is the value of i in MATLAB?

The basic imaginary unit is equal to the square root of -1 . This is represented in MATLAB® by either of two letters: i or j . Thank you for your feedback!

How do you write imaginary parts in MATLAB?

Y = imag( Z ) returns the imaginary part of each element in array Z .

What is 1j in MATLAB?

Description. 1j returns the basic imaginary unit. j is equivalent to sqrt(-1) . You can use j to enter complex numbers. You also can use the character i as the imaginary unit.

Is there a += operator in MATLAB?

Unfortunately there are no increment and compound assignment operators in Matlab.


2 Answers

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.

like image 135
bla Avatar answered Oct 14 '22 06:10

bla


Matlab doesn't have the ++ operator.

However, if you would like to shorten your statement and avoid the temporary variable, you can at least write

srcHoughMatrix(index,jindex,MINIMUM_ALLOWED_RADIUS:end) = ... 
    srcHoughMatrix(index,jindex,MINIMUM_ALLOWED_RADIUS:end) + 1;

(assuming that currentRadius takes on all values from 1 through the 3rd-dimension-size of the array).

like image 5
Jonas Avatar answered Oct 14 '22 07:10

Jonas