if/for loop problem

12 ビュー (過去 30 日間)
Anna
Anna 2011 年 8 月 3 日
so i have this code:
increments=input('Give in the increments between lines in degrees F: ')
disp('F.degrees kelvin')
for i= increments:32:212.0
for z= 0:1:36
z=32+increments*z;
x=z;
y=5*(x-32)/9+273.15;
if x==212
......????
end
fprintf('\n %2.2f %2.2f',x,y);
end
end
but i cant seem to make it work I want the table to stop working when the value of x=212, and im not sure how to stop the loops
any ideas?
so i put in a doc break
increments=input('Give in the increments between lines in degrees F: ')
disp('F.degrees kelvin')
for i= increments:32:212.0
for z= 0:1:36
z=32+increments*z;
x=z;
y=5*(x-32)/9+273.15;
if x==212
doc break;
end
fprintf('\n %2.2f %2.2f',x,y);
end
end
however i get
"Overloaded functions or methods (ones with the same name in other directories) doc simulink/break"
  1 件のコメント
Fangjun Jiang
Fangjun Jiang 2011 年 8 月 3 日
"doc break" is for you to type in Command Window so you can learn about the usage of break(). The actual code you put in place is just break. BTW, you probably should put your condition as x>=212, instead of x==212. Just my guess. Also, look into your variable z. Why is it used for loop index and then over-written in the code?

サインインしてコメントする。

採用された回答

Fangjun Jiang
Fangjun Jiang 2011 年 8 月 3 日
Your inner loop has problem. The variable z is over-written. Probably you meant "for k=0:1:36", instead of "for z=0:1:36"?
  3 件のコメント
Fangjun Jiang
Fangjun Jiang 2011 年 8 月 3 日
You need to know what you are trying to do. I just found an obvious mistake. You are try to do a loop using z as index from 0 to 36 and then you are over-write the variable z!!!
If you are using k as the index, then probably should be z=32+increments*k.
Anna
Anna 2011 年 8 月 3 日
ohh i see it now

サインインしてコメントする。

その他の回答 (1 件)

Sean de Wolski
Sean de Wolski 2011 年 8 月 3 日
perhaps you're looking for break or return
doc break
doc return
?

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by