Replace every 3rd element in a vector with 4 - MATLAB Cody - MATLAB Central

Problem 2990. Replace every 3rd element in a vector with 4

Difficulty:Rate

x is a vector of undetermined length

You are to replace every 3rd element with the number 4, example:

x = [11 23 34 43 2 31 6 34 5 45 26 7 78];

output = [11 23 4 43 2 4 6 34 4 45 26 4 78];

Make sure the code accounts for varying vector lengths

Solution Stats

62.59% Correct | 37.41% Incorrect
Last Solution submitted on Mar 03, 2025

Problem Comments

Solution Comments

Show comments

Problem Recent Solvers253

Suggested Problems

More from this Author28

Problem Tags

Community Treasure Hunt

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

Start Hunting!
Go to top of page