what's wrong with the code
情報
この質問は閉じられています。 編集または回答するには再度開いてください。
古いコメントを表示
for i=1:n
for j=1:n
if (5<i<15 & 8<j<12 & j=i) {d(i,j)=1};
else d(i,j)=0;
end
end
end
1 件のコメント
Youssef Khmou
2013 年 3 月 25 日
Identity matrix In?
回答 (3 件)
Of course, the whole thing could be done much more simply and without loops,
z=zeros(1,n);
z(min(9:11,n))=1;
d=diag(z);
0 件のコメント
Azzi Abdelmalek
2013 年 3 月 25 日
n=40
for i=1:n
for j=1:n
if (5<i & i<15 & 8<j & j<12 & j==i) d(i,j)=1;
else d(i,j)=0;
end
end
end
0 件のコメント
Youssef Khmou
2013 年 3 月 25 日
編集済み: Youssef Khmou
2013 年 3 月 25 日
modify,
for i=1:n
for j=1:n
if (5<i<15 && 8<j<12 && j==i)
d(i,j)=1;
else d(i,j)=0;
end
end
end
1 件のコメント
Walter Roberson
2013 年 3 月 25 日
This has the same bug as the original. 5<i<15 means ((5<i)<15) which means "(true (1) or false (0)) < 15" which is always true.
この質問は閉じられています。
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!