if statement with ge and &

조회 수: 4 (최근 30일)
Robert Demyanovich
Robert Demyanovich 2021년 6월 13일
댓글: Steven Lord 2021년 6월 13일
I don't understand why the following line is producing an error:
if j ge 2 & cANALY(i+1,j-1) < 0
j is a scalar and cANALY(i+1,j-1) is an element in the array cANALY. So why the error "Too many input arguments".

답변 (1개)

Rik
Rik 2021년 6월 13일
You should write this instead:
if j >= 2 && cANALY(i+1,j-1) < 0
  댓글 수: 2
Robert Demyanovich
Robert Demyanovich 2021년 6월 13일
Thanks. It looked like that worked. Coming from a visual basic background, I don't think I'll ever understand MatLab (in this case why the double ampersand??).
Steven Lord
Steven Lord 2021년 6월 13일
If you wanted to use the function form of the operator >= you would have to call it with the two quantities you wanted to compare inside the parentheses.
5 >= 4 % true
ans = logical
1
ge(5, 4) % also true
ans = logical
1
Putting the function between the two inputs won't work. That only works with the operator. Most people just use the operator form, but people writing classes need to know that ge is the function form of the >= operator so they can overload it if necessary.
As for why the double ampersand, read the "More About" section on this documentation page.

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

카테고리

Help CenterFile Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by