Sequence within a sequence
이전 댓글 표시
Hi I want to be able to create a sequence as such
j=1111,2222,3333,4444
It is for use in a loop where j will jump up by 1 for every forth value of i.
thanks
채택된 답변
추가 답변 (3개)
Daniel Shub
2012년 3월 28일
n = 5;
m = 3;
reshape(repmat(1:n, m, 1), n*m, 1)
Dr. Seis
2012년 3월 28일
To beat a dead horse...
I thought I remembered a version by Walter using cumsum, but I couldn't find the link. Here's my attempt to recreate:
n = 5;
m = 3;
a = zeros(m,n);
a(1,:) = 1;
b = cumsum(reshape(a,1,numel(a)));
Running Daniel's test, I got ~0.65 seconds and ~1.05 seconds for the reshape&cumsum and repmat&reshape versions, respectively. However, what you save in compute time is eaten up by doing extra typing.
댓글 수: 1
Daniel Shub
2012년 3월 28일
+1 I knew my answer wouldn't be the fastest. Not only do you have a faster answer, but you also have a faster computer (your answer is faster on my computer also).
Scott
2012년 3월 28일
댓글 수: 2
Daniel Shub
2012년 3월 28일
This is a new question and should be asked as such.
Scott
2012년 3월 28일
카테고리
도움말 센터 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!