필터 지우기
필터 지우기

question using while loop

조회 수: 2 (최근 30일)
Marina Christakos
Marina Christakos 2019년 1월 23일
편집: Stephen23 2019년 1월 23일
variable = input('Continue?', 's');
while variable == 'y'
disp(rand)
variable = input('Continue?', 's');
if (variable ~= 'y')
return
end
end
Need to write a code that if you type 'y', it displays a random variable. If the typed variable is not equal to 'y' then the program should terminate. When I run my code, it keeps displaying "continue?" no matter what variable I type. How would I get this to display a number? (needs to use a while loop)

답변 (1개)

Stephen23
Stephen23 2019년 1월 23일
편집: Stephen23 2019년 1월 23일
v = input('Continue?', 's');
while strcmpi(v,'y')
disp(rand)
v = input('Continue?', 's');
end
When applied to character vectors the equivalence operator == performs an element-wise comparison (as it does on all array types). To compare the complete character vector, use strcmp or strcmpi.

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by