How to replace every other element in an array with a different number
7 次查看(过去 30 天)
显示 更早的评论
I have a vector that I am trying to turn every other entry in the array to be negative.
So it would look like x = [200 -198 196 -194 ... -2 0]
This is what I have. Is there a different approach I should be taking?
x = [200:-2:0]
x(2:2:end) = ()
1 个评论
Stephen23
2020-9-6
编辑:Stephen23
2020-9-6
"I have a vector that I am trying to turn every other entry in the array to be negative."
What should happen if a value is already negative? Is the intent to simply negate values regardless of their signs, or to actually negate absolute values (which matches what you described). So far it is not clear.
采纳的回答
更多回答(1 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!