[英]creating this matrix in matlab
Given 特定
A=[a_1 a_2 a_3 ... a_n]
How to make this? 怎么做?
[a1 ... a100]
[a2 ... a101]
...
[an-100+1 ... an]
I want to not use for-loop here since I want to speed it up. 我不想在这里使用for循环,因为我想加快速度。 Thank you. 谢谢。
You can use: 您可以使用:
n = numel(A);
m = 100;
I = bsxfun(@plus, 1:m, (0:n-m).');
B = A(I);
As a sidenote: The for
loop doesn't perform that bad: 一点题外话:在for
循环不执行不好:
B = zeros(n-m+1, m);
for i = 1:size(B)
B(i,:) = A(i:i+m-1);
end
As far as my testing goes, it is slower only by a factor of 4 and this calculation should hardly be a bottleneck in your program anyway. 就我的测试而言,它仅慢4倍,并且无论如何,此计算都几乎不会成为程序的瓶颈。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.