Replace even element with zero

조회 수: 9 (최근 30일)
Giovanni Rodriguez
Giovanni Rodriguez 2020년 11월 22일
편집: Stephen23 2020년 11월 22일
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
Stephen23
Stephen23 2020년 11월 22일
편집: Stephen23 2020년 11월 22일
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

댓글을 달려면 로그인하십시오.

답변 (1개)

KALYAN ACHARJYA
KALYAN ACHARJYA 2020년 11월 22일
편집: KALYAN ACHARJYA 2020년 11월 22일
"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
Giovanni Rodriguez
Giovanni Rodriguez 2020년 11월 22일
a(2:2:end)=0 makes the even indices = 0. I would like to make the even elements = 0.
KALYAN ACHARJYA
KALYAN ACHARJYA 2020년 11월 22일
a(mod(a,2)==0)=0

댓글을 달려면 로그인하십시오.

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by