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
-
23672 Solvers
-
314 Solvers
-
5879 Solvers
-
Back to basics - mean of corner elements of a matrix
461 Solvers
-
Change the first and last diagonal element of the identity matrix to zero
160 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.