How to construct this vector without loop?
이전 댓글 표시
Hi, everyone:
I was wondering, is it possible to construct following vector without for loop?
A=[1 2 3 1 2 3 4 5 6 1 2 3 4 5 6 7 8 9 .....]
or equivalently A=[1:(3*1), 1:(3*2), 1:(3*3), 1:(3*4), ...., 1:(3*n)]
Many thanks!
채택된 답변
추가 답변 (2개)
Azzi Abdelmalek
2013년 10월 23일
편집: Azzi Abdelmalek
2013년 10월 23일
A=[1 2 3 1 2 3 4 5 6 1 2 3 4 5 6 7 8 9]
cell2mat(arrayfun(@(x) 1:3*x,A,'un',0))
Vivek Selvam
2013년 10월 23일
편집: Vivek Selvam
2013년 10월 23일
vec = 3*(1:n);
A = cell2mat(arrayfun(@(x) 1:x,vec,'UniformOutput',0));
or
vec = 1:n;
A = cell2mat(arrayfun(@(x) 1:3*x,vec,'UniformOutput',0));
카테고리
도움말 센터 및 File Exchange에서 Programming에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!