Problem 45881. Reindex a vector (★★)
(copy of Prob. 676)
You are given two vectors of equal length. Vector N has numeric values (no Inf or NaN) while vector IDX has integers. Place the numerical values in a vector N in the output vector y at indices IDX. All other values in the output vector should be zero.
For example:
N = [1 3 2 7]; IDX= [2 3 4 6];
then
y_correct = [0 1 3 2 0 7];
N(1) goes into y at IDX(1). N(2) goes into y at IDX(2), and so on...
If N is a row vector, your output should be a row vector. If N is a column vector, your output should be a column vector.
Solution Stats
Solution Comments
Show commentsProblem Recent Solvers51
Suggested Problems
-
Maximum running product for a string of numbers
2198 Solvers
-
Is this triangle right-angled?
5987 Solvers
-
Replace every 3rd element in a vector with 4
253 Solvers
-
102 Solvers
-
47 Solvers
More from this Author52
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!