Sequence within a sequence
3 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
Wayne King
2012-3-28
Another way (you need Signal Processing Toolbox)
x = 1:4;
y = upsample(x,4);
h = ones(4,1);
y = filter(h,1,y);
3 个评论
Daniel Shub
2012-3-28
Despite my answer being faster (and I think simpler), I like your answer better from a theoretical vantage.
更多回答(3 个)
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).
另请参阅
类别
在 Help Center 和 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!