How can i create the below Matrix most elegantly using two for loops.
정보
이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.
이전 댓글 표시
|1 8 15|
|2 9 16|
|3 10 17|
|4 11 18|
|5 12 19|
|6 13 20|
|7 14 21|
i tried doing:
for i=1:21;
X = i;
for j=1:3 ;
Matrix[] =[X(i) Y(j)];
댓글 수: 1
Jan
2015년 6월 1일
Please read the "Getting Started" chapters of the documentation at first.
답변 (1개)
Azzi Abdelmalek
2015년 6월 1일
편집: Azzi Abdelmalek
2015년 6월 1일
reshape(1:21,7,[])
댓글 수: 4
Shashank Sharma
2015년 6월 1일
Walter Roberson
2015년 6월 1일
for J = 1 : 1
for K = 1 : 1
Matrix = reshape(1:21,7,[]);
end
end
John D'Errico
2015년 6월 1일
+1. I hate that I cannot vote for a comment. :)
@Shashank Sharma: why do this in two loops? A neater, faster and much more expandable solution is to use Azzi Abdelmalek's original answer. The title of your question is "How can i create the below Matrix most elegantly using two for loops". The most elegant solution is not to use loops, but to use Azzi Abdelmalek's answer.
이 질문은 마감되었습니다.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!