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

3 ビュー (過去 30 日間)
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.

採用された回答

David Hill
David Hill 2020 年 1 月 12 日
M(2:2:end)=-1*M(2:2:end);

その他の回答 (0 件)

カテゴリ

Help Center および File Exchange2-D and 3-D Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by