Tony's trick for duplicating an mx1 vector n times - MATLAB Cody - MATLAB Central

Problem 2012. Tony's trick for duplicating an mx1 vector n times

  • Created by Ted
Difficulty:Rate

Without using repmat, or for loop, or concatenation, create a function to duplicate a vector, v, a specified number of times, n. v can be numeric or character. n may be 0.

Examples

If

 v = 5;
 n = 3;

then return v1:

 v1 = [5 5 5] 

If a 2d matrix is supplied then the vector v will be the first column.

 V = magic(4);
 n = 4;

then v and v1 are returned as shown below.

 v = [16 5 9 4]'
 v1 = [16 16 16 16; 5 5 5 5; 9 9 9 9; 4 4 4 4] 

Hint: use indexing

Solution Stats

51.52% Correct | 48.48% Incorrect
Last Solution submitted on Apr 07, 2023

Problem Comments

Solution Comments

Show comments
R2025a Pre-release highlights
This topic is for discussing highlights to the current R2025a Pre-release.
12
4

Problem Recent Solvers52

Suggested Problems

More from this Author11

Community Treasure Hunt

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

Start Hunting!
Go to top of page