Vector pop - MATLAB Cody - MATLAB Central

Problem 44490. Vector pop

Difficulty:Rate

Take n elements from the end of the vector v and return both the shorten vector v and the n elements in a separate vector w.

If v has less elements than n, the shorten vector v should be empty and all elements should exist in w.

Example 1

v = 1:10
[v, w] = pop(v, 3);

Then:

v = 1:7
w = 8:10

Example 2

v = [1; 2; 3]
[v, w] = pop(v, 5);

Then:

v = []
w = [1; 2; 3]

Solution Stats

29.36% Correct | 70.64% Incorrect
Last Solution submitted on Jun 28, 2025

Problem Comments

Solution Comments

Show comments
Why should you share code?
In a discussion on LInkedin about my recent blog post, Do these...
2
3

Problem Recent Solvers394

Suggested Problems

More from this Author25

Problem Tags

Community Treasure Hunt

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

Start Hunting!