I have a matrix a=[1,2,3,4​..........​,20], Now I want to multiply every other element in a with -1 to get a=[1,-2,3,​-4........​........-2​0].

9 views (last 30 days)
I have a matrix a=[1,2,3,4..........,20] Now I want to multiply every other element in 'a' with -1 to get a=[1,-2,3,-4................-20]. please help me with this......!!

Accepted Answer

Matt J
Matt J on 9 Nov 2013
a(2:2:end)=-a(2:2:end);

More Answers (0)

Categories

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