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
.
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
.
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.
Increment / Decrement operators are not implemented in matlab.
There are reasons to keep a language as simple as possible. For c there are long discussions about undefined behaviour using these operators. Mathworks support also pointed out similar reasons not to implement these operators.