フィルターのクリア

Replace string values with another string value.

1 回表示 (過去 30 日間)
Kaushik Vasanth
Kaushik Vasanth 2019 年 3 月 4 日
コメント済み: Kaushik Vasanth 2019 年 3 月 7 日
I am trying to assign value for the string data.
for eg :
0 = 00000
1 = 00001
-1 = 11111 (2's complement)
I have the data in the format 0 0 0 1 1 2 0 -1 -3 and so on. It ranges from -8 to 8 . And now I want to assign 5bit binary equivalent for the same.
But when I use "regexprep(y1,{'0','1','2','3'},{'00000','00001','00010','00011})" I get the right values for the positive numbers but when I try to assign the same for negative scale it takes the '-' sign and displays the value of 1. For eg: if my input is regexprep(y1,{'-1'},{'11111'}) but i get output as '-00001'. I have attached the pictures in the same.
Looking forward to your support.

採用された回答

dpb
dpb 2019 年 3 月 4 日
fntwoscomp=@(v,n) dec2bin(mod(v,2.^n),n);
>> fntwoscomp(-3:3,5)
ans =
7×5 char array
'11101'
'11110'
'11111'
'00000'
'00001'
'00010'
'00011'
>>
  5 件のコメント
dpb
dpb 2019 年 3 月 6 日
Glad to help...sometimes one has to revisit the idea of what the problem is one is trying to solve! :)
If the solution solves the problem, please go ahead and Accept the answer so it can be seen to be closed by others looking either to help or that might actually search for similar topic...
Kaushik Vasanth
Kaushik Vasanth 2019 年 3 月 7 日
Yes, thats so true. The right way to commuicate the issue is a bigger problem :)
Thanks a lot for your feedback :)

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

その他の回答 (0 件)

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by