[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.

 채택된 답변

data = [1.295175 -0.021158 -0.274017];
data(data<0)=0;
data(data>1)=1
data = 1×3
1 0 0

댓글 수: 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...
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
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"....
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].
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
Hohoho wow.
Thank a lot, Arif Hoq.
It's all work well.
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