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!