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 CenterFile Exchange에서 2-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