How can I replace integer values in a array?

2 次查看(过去 30 天)
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

Image Analyst
Image Analyst 2021-1-3

类别

Help CenterFile Exchange 中查找有关 Resizing and Reshaping Matrices 的更多信息

产品


版本

R2014b

Community Treasure Hunt

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

Start Hunting!

Translated by