Skipping input prompt before loop
3 次查看(过去 30 天)
显示 更早的评论
I am new to this, so Im sorry if this is an excessively mundane question, but Im just a little confused. I have a script I need to execute with a user-defined starting number, but matlab skips my input prompt entirely and then errors, presumably because there's no set value for my variable because I intended for it to be defined in the prompt.
x=input('Choose positive number')
while x>1;
if rem(x,2)=0
x/2=x;
elseif rem(x,2)=1
3x+1=x;
end
end
Why does matlab skip my input prompt here?
0 个评论
回答(3 个)
Azzi Abdelmalek
2014-2-22
First error: if rem(x,2)=0 (use ==)
second error: x/2=x; what is this?
0 个评论
Kyle
2014-2-22
编辑:Kyle
2014-2-22
2 个评论
Image Analyst
2014-2-22
A steep learning curve is great and very much desired. If you plot "amount learned" as a function of time, don't you want a very steep curve? It's good that you have a steep learning curve with MATLAB.
Jan
2014-2-22
@Kyle: Please post comments to answers in the corresponding comment section, not as a new answer.
The assignment operator = assigns the result of the expression on the right side to the variable on the left side. Therefore x/2=x is not valid, because there is an expression on the left side.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!