How to shift a vector using 'for' loop

14 views (last 30 days)
Dear members
Firstly,I have many vectors for example (V1, V2, V3, V4 ...) of M length.
How can I use 'for' loop to obtain firstly [V1 V2] then [V2 V3] then [V3 V4], [V4 V5] ... etc. It means I shift the previous vector each time.
Thank you.
Afluo Raoual
Afluo Raoual on 5 Mar 2021
No, I found them using many operations not just by hand

Sign in to comment.

Accepted Answer

Stephen23 on 5 Mar 2021
Edited: Stephen23 on 5 Mar 2021
Store all of the vectors in one cell array (which they should be anyway):
C = {V1, V2, V3, V4 ...};
then all you need is this loop:
for k = 2:numel(C)
or even just this:
for k = 2:numel(C)
[C{k-1:k}] % comma-separated list and concatenation
  1 Comment
Afluo Raoual
Afluo Raoual on 5 Mar 2021
Thank you. I appreciate your help

Sign in to comment.

More Answers (0)


Find more on Startup and Shutdown in Help Center and File Exchange


Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!