Borrar filtros
Borrar filtros

Replace string values with another string value.

1 visualización (últimos 30 días)
Kaushik Vasanth
Kaushik Vasanth el 4 de Mzo. de 2019
Comentada: Kaushik Vasanth el 7 de Mzo. de 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.

Respuesta aceptada

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

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Logical en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by