replace not selected value by zero
Show older comments
Hi I have 10 values. my code select 3 values, for example, if x=[1 2 3 4 5 6 7 8 9 10] and my code select [1 3 5] i want a code to do this x= [1 0 3 0 5 0 0 0 0 0]?.
Accepted Answer
More Answers (1)
Image Analyst
on 28 Jan 2018
Here's one way:
x=[1 2 3 4 5 6 7 8 9 10]
mask = [1 3 5]
x2 = zeros(1, length(x)); % Initialize x2
x2(mask) = x(mask) % Pull over values in the mask from x and put them in the same column.
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!