Change sign of every second element of a vector
Show older comments
Hi,
I want to change the sign of every second element in a vector, starting from element two. I tried the following code. Can someone explain why it does not work and help me to fix it? Thank you!
function newVector = change(v)
for i = 1:length(v)-1
newVector(i) = v(i);
newVector(i+1) = v(i+1)*-1;
end
v = newVector
end
1 Comment
madhan ravi
on 22 Mar 2019
Edited: madhan ravi
on 22 Mar 2019
@KSSV: Why did you delete my comment ? 


Accepted Answer
More Answers (0)
Categories
Find more on Seismology 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!