C-like operations
4 views (last 30 days)
Show older comments
I wonder wether Matlab could include a form of arithmetic operations common in C, namely x+=y, x*=y, x/=y etc.
In the piece of code
ctrl = somevar <= someother;
x(ctrl) = -x(ctrl);
indexing takes place twice, while x(ctrl)*= -1; could possibly save some time, unless the optimization of the Matlab interpreter makes this idea obsolete.
Anybody has an answer? Thanks
Answers (1)
Aiswarya Subramanian
on 5 Jul 2019
Hello Enrico,
Such operations are not supported by MATLAB. You can go through the post 11 ( Steven Lord's answer ) I have attached below, which says that since MATLAB is array based, such operator would be ambiguous and unintuitive.
Hope it helps :)
1 Comment
Stephen23
on 8 Jul 2019
Enrico Onofri's "Answer" moved here:
I believe that a scalar operation like v= v*a should be simply v*=a at no risk (v matrix, a scalar). Also V(indices)*=a ; would be better than V(indices)=V(indices)*a. Where is the danger? I’m not convinced! Thanks anyway.
See Also
Categories
Find more on Get Started with MATLAB in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!