Effacer les filtres
Effacer les filtres

How to shift a vector using 'for' loop

3 vues (au cours des 30 derniers jours)
Afluo Raoual
Afluo Raoual le 5 Mar 2021
Commenté : Afluo Raoual le 5 Mar 2021
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 commentaires
Stephen23
Stephen23 le 5 Mar 2021
"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?
Afluo Raoual
Afluo Raoual le 5 Mar 2021
No, I found them using many operations not just by hand

Connectez-vous pour commenter.

Réponse acceptée

Stephen23
Stephen23 le 5 Mar 2021
Modifié(e) : Stephen23 le 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)
[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
  1 commentaire
Afluo Raoual
Afluo Raoual le 5 Mar 2021
Thank you. I appreciate your help

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by