Vector push - MATLAB Cody - MATLAB Central

Problem 44486. Vector push

Difficulty:Rate

Append an element x to the end of the vector v and return both the extended vector and the new number of its elements. x can be a vector as well.

In cases where v is a row vector and x is a column vector, or vice versa, v should remain a row/column vector. When v is originally empty, it should preserve the dimensions of x.

For example:

v = 1:5;
[v, n] = push(v, [6;7;8]);

Results in:

v = 1:8;
n = 8;

Solution Stats

17.24% Correct | 82.76% Incorrect
Last Solution submitted on Mar 11, 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 Solvers397

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!