필터 지우기
필터 지우기

what is difference between C=+A, C=A, C=unary(A)? All three provide same assignment of matrix A to C

조회 수: 2 (최근 30일)
I cant understand the difference between C=+A, C=A, C=unary(A)?
All three provide same assignment of matrix A to C. Is there any difference among them

채택된 답변

Chunru
Chunru 2021년 7월 27일
편집: Chunru 2021년 7월 29일
C=+A;
C = uplus(A) is an alternate way to execute +A, but is rarely umeased. It enables operator overloading for classes.
So depending on class of A, +A or uplus(A) may have different meaning.
C = A; This is just an assignment.
[Update based on comments below]
For assignment:
  • C = A; This is assiment only. MATLAB will do a lazy copying (pointer to A) and only do the real data copying when C is changed later.
  • C = +A or C=uplus(A); +A and uplus(A) is the expression or function that involves A. The meaning of + and uplus is class dependent. The expression and function need to be evaluated first before assignment. The evaluation results is assigned to C (data copying is necessary).
The meaning of +/upluse:
  • For numerical data types like double/single/etc, this will have no effect of the results.
  • For logical and char, +/upluse has the effect of operator overloading. The result is of numerical data type double.
As function input arguments:
  • +A and uplus(A) is the expression, as in table(+A)
In addition, it is possible (but rarely) for user to do the operater overloading of +/uplus.
  댓글 수: 5
Steven Lord
Steven Lord 2021년 7월 28일
That's true, I'd forgotten about char. I guess I was a little more tired than I thought when I wrote that response.

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

추가 답변 (1개)

Palguna Gopireddy
Palguna Gopireddy 2021년 7월 30일
Thanks for the help.

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by