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].
Show older comments
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......!!
Answers (1)
Azzi Abdelmalek
on 9 Nov 2013
Edited: Azzi Abdelmalek
on 9 Nov 2013
a=1:20
a(2:2:end)=- a(2:2:end)
Categories
Find more on Creating and Concatenating Matrices 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!