I want to convert the following vector A
into matrix B
, best demonstrated by this example:
n = 4;
A = [1 2 3 4 5 6];
B = [ 1 2 3 4;
2 3 4 5;
3 4 5 6; ]
I am currently using a loop to achieve this and wondered if it was possible to vectorize it?
Thanks L.
If you have the Signal Processing Toolbox you can also use convmtx
:
n = 4;
A = [1 2 3 4 5 6];
m = numel(A)-n;
B = flipud(convmtx(A,m+1));
B = B(:,m+1:end-m);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.