Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the syntax of `i++` in Matlab [duplicate]

Is there a shortcut statement that would do what C code i++ would do? (that is to increase i by 1)?

Of course i do not mean the obvious i = i + 1.

like image 974
Giacomo Alessandroni Avatar asked Jan 18 '26 16:01

Giacomo Alessandroni


1 Answers

No, you cannot do this in Matlab. To increment a variable, you must use i = i + 1;.


Edit - If you were really desperate for something like this, you could define a function that looked like

function increment(x)
    evalin('caller', sprintf('%s = %s + 1;', x, x));
end

and call it like this

>> x = 1;
>> increment x;
>> x
x =
    2

however this would be (a) confusing and (b) slow.

like image 173
Chris Taylor Avatar answered Jan 21 '26 08:01

Chris Taylor



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!