필터 지우기
필터 지우기

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 CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by