My textbook gave me code that has an error I don't know how to fix

조회 수: 1 (최근 30일)
Emma C
Emma C 2019년 3월 27일
댓글: Emma C 2019년 3월 27일
if flag==1 && alt>=30000
fprintf('Normal operation at %0.0f feet.\n',alt)
elseif flag==0 || alt==0
fprintf('On Ground')
elseif flag==2 && alt < 30000
fprintf('Currently at %0.0f feet and climbing\n',alt)
elseif flag==3
fprintf('Currently at %0.0f feet and descending\n',alt)
else
fprintf('Status transitional')
end
Please here is the code!
This is the error I'm getting
Operands to the || and && operators must be convertible
to logical scalar values.
Error in Homework4q5 (line 3)
if flag==1 && alt>=30000

채택된 답변

Catalytic
Catalytic 2019년 3월 27일
편집: Catalytic 2019년 3월 27일
alt and flag must be scalars.
  댓글 수: 3
Catalytic
Catalytic 2019년 3월 27일
편집: Catalytic 2019년 3월 27일
It's not giving me any problems.
flag = 1; alt = 25000;
if flag==1 && alt>=30000
fprintf('Normal operation at %0.0f feet.\n',alt)
elseif flag==0 || alt==0
fprintf('On Ground')
elseif flag==2 && alt < 30000
fprintf('Currently at %0.0f feet and climbing\n',alt)
elseif flag==3
fprintf('Currently at %0.0f feet and descending\n',alt)
else
fprintf('Status transitional')
end
disp ' '
Running this gives me
Status transitional
Emma C
Emma C 2019년 3월 27일
Thank you I realized what I was doing wrong, I had the flag and alt values after the code. Its been a long day

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Multirate Signal Processing에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by