Given numeric vectors x, a and b, perform the following operation -
a represents a vector of numbers and b represents a vector of indices; corresponding to the values in b, add the values of a to x.
Examples -
Input
x = [1 2 3 4]
a = [1 2 3]
b = [1 2 1]
Output
y = [5 4 3 4]
Explaination - Add a(1) to x(b(1)), a(2) to x(b(2)) and so on.
Input
x = [3; 5; 7; 9]
a = [-2; 0; 2]
b = [4; 4; 1]
Output
y = [5; 5; 7; 7]
Note - Values in x and a will belong to Real numbers, values in b will be Integers in the range [1, numel(x)]. Test suite will be updated regularly.
Restrictions - loops and recursion are not allowed.

Solution Stats

34 Solutions

8 Solvers

Last Solution submitted on Sep 22, 2025

Last 200 Solutions

Problem Comments

Solution Comments

Show comments
Loading...

Problem Recent Solvers8

Suggested Problems

More from this Author44

Community Treasure Hunt

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

Start Hunting!