Replace even element with zero

28 ビュー (過去 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

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeResizing and Reshaping Matrices についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by