While loop that stops if certain number is inserted
이전 댓글 표시
I'm stuck trying to code a while loop that stops given a certain number. I'm a complete beginner at matlab, but i have searched the community and youtube and managed, until now.
This part I get to work:
while true a==1,2,3,4,6,7,8,9,10,
x=a+1;
end
ans=x
and I do get it to stop and wait for input by
while true a==1,2,3,4,6,7,8,9,10,
input('I stop when given the number 5: ',x) % by adding this line
x=a+1;
end
ans=x
BUT if i try to make it stop when given the number 5 I cannot for the life of me get it to work properly.
while true a==1,2,3,4,6,7,8,9,10,
input('I stop when given the number 5: ',x)
if x==5;
break
end
x=a+1;
end
ans=x
답변 (1개)
John D'Errico
2023년 2월 23일
편집: John D'Errico
2023년 2월 23일
You should read the help for while. What you wrote was not even close to valid MATLAB syntax. Look at the examples found in the help docs.
For example, what might this do?
x = 0;
while x ~= 5
Then inside the while loop, use input to bring in a new value for x.
카테고리
도움말 센터 및 File Exchange에서 Startup and Shutdown에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!