Replace even element with zero

30 views (last 30 days)
Giovanni Rodriguez
Giovanni Rodriguez on 22 Nov 2020
Edited: Stephen23 on 22 Nov 2020
Hi.
I am trying to replace even elements in my matrix with zero like below:
a = [3 5 4 1 2]
enter magical code here
a = [3 5 0 1 0]
Any help would be greatly appreciated
  1 Comment
Stephen23
Stephen23 on 22 Nov 2020
Edited: Stephen23 on 22 Nov 2020
Original question by Giovanni Rodriguez:
Replace even element with zero
Hi.
I am trying to replace even elements in my matrix with zero like below:
a = [3 5 4 1 2]
enter magical code here
a = [3 5 0 1 0]
Any help would be greatly appreciated

Sign in to comment.

Answers (1)

KALYAN ACHARJYA
KALYAN ACHARJYA on 22 Nov 2020
Edited: KALYAN ACHARJYA on 22 Nov 2020
"I am trying to replace even elements in my matrix with zero like below:"
a(2:2:end)=0
But the example is different ??
a = [3 5 0 1 0]
  2 Comments
Giovanni Rodriguez
Giovanni Rodriguez on 22 Nov 2020
a(2:2:end)=0 makes the even indices = 0. I would like to make the even elements = 0.

Sign in to comment.

Categories

Find more on Resizing and Reshaping 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!