counter with if,elseif condition

조회 수: 5 (최근 30일)
DEEKSHA GUPTA
DEEKSHA GUPTA 2018년 2월 15일
답변: Abhishek Kumar 2019년 7월 11일
Hello,I am using counter with if,elseif condition but result is not expected,becoz i want ouput=1 for first 32 counter,then output=2 for next 32 count,then output=3 for next 32 count,but according to MATLAB result it is comming 1 for first 32 counter and output=2 for remaining count.

답변 (1개)

Abhishek Kumar
Abhishek Kumar 2019년 7월 11일
for loop=1:200
if(loop<=32)
p(loop)=1;
elseif(loop<=64)
p(loop)=2;
elseif(loop<=96)
p(loop)=3;
elseif(loop<=128)
p(loop)=4;
elseif(loop<=160)
p(loop)=5;
end
end
Use this code. it works fine.
In the 'elseif' after the if block, it is already assured that loop is greater than 32. And even if you want to write it explicitly the correct way would be:
elseif(loop>32 && loop<=64)

카테고리

Help CenterFile Exchange에서 Parametric Spectral Estimation에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by