Why is the code not implementing for i==6 value ?

T = zeros(7,12);
for i = 1:7
for j = 1:12
if (i==1 || i==7)
T(i,j) = 1750;
end
if i==4 && (j>3 && j<9)
T(i,j) = 600;
end
if (i==2 || i==6) && (j>1 && j<11)
T(i,j) = (T(i+1,j)+T(i,j+1)+T(i-1,j)+T(i,j-1))/4;
end
end
end
Any help would be appreciated.

3 件のコメント

Aryaman
Aryaman 2014 年 9 月 30 日
Any help regarding why the code is not implementing at i == 6 value, would be appreciated.
Image Analyst
Image Analyst 2014 年 10 月 1 日
See http://www.mathworks.com/matlabcentral/answers/13205-tutorial-how-to-format-your-question-with-markup. Also learn to use control-I to properly indent your code before pasting it in here (then highlighting and clicking {}Code button). And take Roger's good advice and paste your properly formatted code back here if you still have problems.
Aryaman
Aryaman 2014 年 10 月 1 日
Dear Sir, thank you for your advice. I am still new to this portal and am learning to make the best use of it. Sorry for the inconvenience.

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

 採用された回答

Roger Stafford
Roger Stafford 2014 年 10 月 1 日

2 投票

I see one apparent error. The condition (i==1 i==7) will never be true. You need an 'or' symbol in it: (i==1 | i==7).
Also notice that when i is equal to 6, T(i+1),j) will not have been set to 1750 as yet, so the expression
T(i,j) = (T(i+1,j)+T(i,j+1)+T(i-1,j)+T(i,j-1))/4;
may not give you the value you expect. To correct this will require rewriting the routine. Set up your 1750's and 600's first, then do the computation for i==2 | i==6.

1 件のコメント

Aryaman
Aryaman 2014 年 10 月 1 日
Thank you Roger,I was able to resolve the problem and proceed further.

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeVariables についてさらに検索

タグ

質問済み:

2014 年 9 月 30 日

コメント済み:

2014 年 10 月 1 日

Community Treasure Hunt

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

Start Hunting!

Translated by