How do you make every other integer in an array equal to 0 in matlab?
arrays, matlab
Solution
This should do that:
Y(2:2:end) = 0;
With this line you basically say each element starting from the seconds up to the last, in steps of two, should be zero. This can be done for larger steps too:, `Y(N:N:end) = 0` makes every `N`th element equal to 0.
Problem
Lets say I have an array ``` Y = [1, 2, 3, 4, 5, 6] ``` I want to make a new array that replaces every other number with 0, so it creates ``` y = [1, 0, 3, 0, 5, 0] ``` How would I go about approaching this and writing code for this in a efficient way?