How to shift a vector using 'for' loop
조회 수: 2 (최근 30일)
이전 댓글 표시
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.
댓글 수: 2
Stephen23
2021년 3월 5일
"I have many vectors for example (V1, V2, V3, V4 ...)"
How did you get them all into the workspace? Did you name them all by hand?
채택된 답변
Stephen23
2021년 3월 5일
편집: Stephen23
2021년 3월 5일
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)
[C{k-1},C{k}]
end
or even just this:
for k = 2:numel(C)
[C{k-1:k}] % comma-separated list and concatenation
end
추가 답변 (0개)
참고 항목
카테고리
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!