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
Problem Comments
2 Comments
Solution Comments
Show comments
Loading...
Problem Recent Solvers8
Suggested Problems
-
Return unique values without sorting
1001 Solvers
-
Generate a string like abbcccddddeeeee
275 Solvers
-
The sum of the numbers in the vector
642 Solvers
-
759 Solvers
-
Find the area of the four walls
292 Solvers
More from this Author44
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
I am very confused by your explanation. b will be integers in the range [1, numel(x)], doesn't the second example violate this (where b has -2 and 0 as members)? I still don't see how you are getting your output with the explanation provided.
There was some mishap in that example, David. b was supposed to be a (and vice-versa), as you pointed out the violation.
It has been cleared out. I hope the question is clear now.