List(Vecor) Generation
조회 수: 4 (최근 30일)
이전 댓글 표시
Can I generate list [1 2 3 2 3 4 3 4 5 4 5 6 ....] without for loop?
Thanks!
댓글 수: 0
채택된 답변
madhan ravi
2019년 9월 8일
m=3; % pairs
n=4; % n combinations
reshape((0:n-1)+(1:m)',1,[])
댓글 수: 1
madhan ravi
2019년 9월 8일
If you're using version prior to 2016b:
% last line would be
reshape(bsxfun(@plus,(0:n-1),(1:m)'),1,[])
추가 답변 (2개)
Andrei Bobrov
2019년 9월 8일
편집: Andrei Bobrov
2019년 9월 8일
m=3;
n=4;
T = 1:m*n;
out = ceil(T/m) + mod(T-1,m);
or
out = floor(T/n) + mod(T-1,m) + 1;
or
out = repmat(1:m,1,n) + repelem(0:n-1,m);
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Dijkstra algorithm에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!