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

3 vues (au cours des 30 derniers jours)
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.

Réponse acceptée

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

Plus de réponses (0)

Catégories

En savoir plus sur 2-D and 3-D Plots dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by