필터 지우기
필터 지우기

C-like operations

조회 수: 2 (최근 30일)
Enrico Onofri
Enrico Onofri 2019년 7월 5일
댓글: Stephen23 2019년 7월 8일
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

답변 (1개)

Aiswarya Subramanian
Aiswarya Subramanian 2019년 7월 5일
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
Stephen23
Stephen23 2019년 7월 8일
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.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Introduction to Installation and Licensing에 대해 자세히 알아보기

태그

제품


릴리스

R2019a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by