필터 지우기
필터 지우기

for loops and the if statement

조회 수: 4 (최근 30일)
Brenden
Brenden 2011년 7월 4일
답변: sourav malla 2019년 6월 26일
This is a beginner question im sure i just dont understand why is it that i have to use 2 equal signs in the if statement?
for n=0:10;
fprintf('n=%d\n',n);
if n==0
i cannot use n=0 ??
thanks BN

채택된 답변

bym
bym 2011년 7월 4일
n=0
Is an assignment; it assigns the value 0 to the variable n
n==0
is a logical test; it tests whether the variable n is equal to 0 and returns a boolean (true/false)

추가 답변 (1개)

sourav  malla
sourav malla 2019년 6월 26일
If you are assigning something inside the loop then its:
z=0;
And if you are checking a statement for true or false then:
z==0;
basically it will return logical 1 or 0 based upon 'true' or 'false' in matlab.

카테고리

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

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by