フィルターのクリア

How can I replace integer values in a array?

1 回表示 (過去 30 日間)
Noman Abir
Noman Abir 2021 年 1 月 3 日
回答済み: Image Analyst 2021 年 1 月 3 日
I Have some values in a array like this.
A = -4
-4
-4
4
4
4
I want to convert all negative values to 0 and all positive values to 1.
How can I do that.??
Outcome should be :
B = 0
0
0
1
1
1

回答 (2 件)

Matt J
Matt J 2021 年 1 月 3 日
編集済み: Matt J 2021 年 1 月 3 日
B=(sign(A)+1)/2
  1 件のコメント
William
William 2021 年 1 月 3 日
... but be aware that sign(0)=0, so B becomes 0.5 in this case.

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


Image Analyst
Image Analyst 2021 年 1 月 3 日

カテゴリ

Help Center および File ExchangeNumeric Types についてさらに検索

製品


リリース

R2014b

Community Treasure Hunt

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

Start Hunting!

Translated by