representation of positive and negative number to binary 1 and 0 in matlab

6 ビュー (過去 30 日間)
Ayesha Punjabi
Ayesha Punjabi 2018 年 10 月 18 日
編集済み: Guillaume 2018 年 10 月 19 日
  • I have a column which has negative and positive values say
  • volts = -5.2 -5.2 8.4 8.4 8.4 8.4 -5.2 5.2
  • i have to represent positive number as 1 and negative number as 0. How should I write a statement for it in matlab??

回答 (1 件)

James Tursa
James Tursa 2018 年 10 月 18 日
編集済み: James Tursa 2018 年 10 月 18 日
result = volts > 0;
This will give you a logical result. If you need the result to be double, then simply
result = double(volts > 0);
You didn't specify what you wanted to happen to 0.
  2 件のコメント
Ayesha Punjabi
Ayesha Punjabi 2018 年 10 月 19 日
編集済み: Guillaume 2018 年 10 月 19 日
>> volts = ((-5 + 10*(out0))*0.35);
>> volts1 = ((-5 + 10*(out1))*1.4);
>> voltsadd = volts + volts1;
>> x(x>=0) = [1]
>> x(x<=0) = [0]
I was trying the above example. Basically my target was to replace the negative numbers with 0 and positive with 1
now I have 2 results results of out0 has [1111000011110000] and out1 has [1111111111111111] (total 16 bits) how would I predict that final data value from out 1 is 1 if it has more number of 1 (i.e if the consistency of 1 is more) and final data value as 0 if its inconsistent)
James Tursa
James Tursa 2018 年 10 月 19 日
I don't understand your latest question.

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

Community Treasure Hunt

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

Start Hunting!

Translated by