Effacer les filtres
Effacer les filtres

Replace string values with another string value.

1 vue (au cours des 30 derniers jours)
Kaushik Vasanth
Kaushik Vasanth le 4 Mar 2019
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.

Réponse acceptée

dpb
dpb le 4 Mar 2019
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 commentaires
dpb
dpb le 6 Mar 2019
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 le 7 Mar 2019
Yes, thats so true. The right way to commuicate the issue is a bigger problem :)
Thanks a lot for your feedback :)

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by