oN is a array Logical
col is array Logical
why is not correct using &?
K>> class(oN)
ans =
'logical'
K>> class(col)
ans =
'logical'

 채택된 답변

Stephen23
Stephen23 2024년 2월 13일
편집: Stephen23 2024년 2월 13일

0 개 추천

"why is not correct using &?"
Who says that it is not "correct" ? What you show is not a code error (underlined in red), it is a recommendation (underlined in orange)
Benefits:
  • For scalar values && is (in general) faster than & because it only evaluates the right argument if the left argument is TRUE.
  • Defensive programming: by using && you assert that its arguments are scalar. If later they are erroneously not scalar then && will stop with an error (rarher than continuing in some unknown state).
  • Clarity to the reader
If you want to ignore this recommendation then right-click and select one of the "ignore" options.

댓글 수: 3

shamal
shamal 2024년 2월 13일
편집: shamal 2024년 2월 13일
The array is a logical type so the correct use of the operator is to use the "&" for logical operations.
"&&" if they are scalars but this is not the data type in question
Stephen23
Stephen23 2024년 2월 13일
편집: Stephen23 2024년 2월 13일
"The array is a logical type so the correct use of the operator is to use the "&" for logical operations.
You just invented that rule yourself: there is no rule saying that scalar values must use &.
In contrast the static code parser is written by the people who actually develop MATLAB.
""&&" if they are scalars but this is not the data type in question"
MATLAB does not have a "scalar" data type, they are all arrays:
Most likely the data in question is scalar: assuming that k is a scalar subscript then both of the arguments to && will be scalar, and the recommendation is completely appropriate. That is most likely what the static parser has detected. Your invention of non-existent data types and non-existent rules does not help you.
Question: what size do oN(k) and col(k) have?
shamal
shamal 2024년 2월 13일
ok thank..i understand

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Structures에 대해 자세히 알아보기

질문:

2024년 2월 13일

편집:

2024년 2월 13일

Community Treasure Hunt

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

Start Hunting!

Translated by