I want to perform a function on the values that are on the even positions of my vector

1 view (last 30 days)
Hello,
I have a vector that begins at 1 and ends at 89 where the spacing between each number is 4. So, it looks like [1,5,9,13,17,...,89]. What is want to do with this vector is mulitply -1 to only the values in an even position of the vector. What I want essentially is [1,-5,9,-13,....-85,89]. How can I go about doing this? Any advice is appreciated. Thank you.

Accepted Answer

David Hill
David Hill on 12 Jan 2020
M(2:2:end)=-1*M(2:2:end);

More Answers (0)

Categories

Find more on 2-D and 3-D Plots 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!