Make the vector lin=[1 2 3 ⋯ 20] (the integers from 1 to 20), and then make every other value in it negative to get lin=[1 −2 3 −4 ⋯ −20] . what is the MATLAB code?

45 views (last 30 days)
lin=[1:20]
then?

Accepted Answer

Matt J
Matt J on 11 Jul 2015
lin(2:2:end)=-lin(2:2:end)
  1 Comment
Orbay Altuntoprak
Orbay Altuntoprak on 27 Feb 2016
Having looked through google for the answer to the question stated above, I was very delighted to find your answer. Thank you.

Sign in to comment.

More Answers (1)

Azzi Abdelmalek
Azzi Abdelmalek on 11 Jul 2015
Edited: Azzi Abdelmalek on 11 Jul 2015
a=-(1:20)
Read the documentation

Categories

Find more on Programming 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!