[Ask Help] - Convert Negative Commas Decimal into Single Binary

Hello,
Is anyone please could help me to convert this data from (Negative Commas Decimal).
Maximum set to '1' and other set to '0 or zero'.
This is my data:
data = [1.295175 -0.021158 -0.274017]
And i wanna convert into single binary like this :
data = [ 1 0 0 ]
Thanks.

 採用された回答

Arif Hoq
Arif Hoq 2022 年 12 月 8 日
data = [1.295175 -0.021158 -0.274017];
data(data<0)=0;
data(data>1)=1
data = 1×3
1 0 0

8 件のコメント

Hilmi
Hilmi 2022 年 12 月 8 日
this is my data
and i'm still getting error using this :
data(data<0)=0;
data(data>1)=1
data = 1x3
please help me,
thanks...
Arif Hoq
Arif Hoq 2022 年 12 月 8 日
編集済み: Arif Hoq 2022 年 12 月 8 日
what kind of binary value do you want for [0.262483 0.749615]? 0 or 1?
data=[0.262483 0.749615 -0.012098];
data(data<0)=0;
data(data>0 & data<1)=1;
data(data>1)=1
data = 1×3
1 1 0
Hilmi
Hilmi 2022 年 12 月 8 日
thanks, now i have data like this, and i wanna convert to [ 1 0 0 ]
0.262483
0.749615
-0.012098
just only convert into "1" on maximum data...
and convert others convert into "0/zero"....
Arif Hoq
Arif Hoq 2022 年 12 月 8 日
I don't get your logic. 0.749615 is greater than 0.262483.
if you want the maximum data into 1 then [0.262483 0.749615 -0.012098] would be [0 1 0].
Hilmi
Hilmi 2022 年 12 月 8 日
oh ya i'm sorry [0.262483 0.749615 -0.012098] should be [0 1 0].
maybe i just wanna convert data like that
  • only convert data maximum into '1'
  • and convert others into '0'
and i've many data below:
data1 =
0.2114
-0.1044
0.8930
data2 =
0.1854
0.3776
0.4370
data3 =
0.2857
-0.5430
1.2574
data4 =
0.026814
0.295099
0.678087
data5 =
0.1420
-0.1536
1.0116
what should i do? thankss...
try this:
data1=[0.2114 -0.1044 0.8930];
[M I]=max(data1);
data1(I)=1;
data1(data1~=1)=0
data1 = 1×3
0 0 1
%% data2
data2 =[ 0.1854 0.3776 0.4370];
[M I]=max(data2);
data2(I)=1;
data2(data2~=1)=0
data2 = 1×3
0 0 1
%% data3
data3 =[ 0.2857 -0.5430 1.2574];
[M I]=max(data3);
data3(I)=1;
data3(data3~=1)=0
data3 = 1×3
0 0 1
Hilmi
Hilmi 2022 年 12 月 8 日
Hohoho wow.
Thank a lot, Arif Hoq.
It's all work well.
Arif Hoq
Arif Hoq 2022 年 12 月 8 日
my pleasure

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

その他の回答 (0 件)

カテゴリ

質問済み:

2022 年 12 月 8 日

コメント済み:

2022 年 12 月 8 日

Community Treasure Hunt

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

Start Hunting!

Translated by