how to have character replacement
이전 댓글 표시
every digit is converted to binary and are grouped with two bits each and i have to replace it with characters.
example A=11000100
i have to replace as
if
11 then 'A'
00 'C'
01 'G'
10 'T'
final result should be a=ACGT
I have written a code it takes long time to get executed
bi = dec2bin(secret,8) - '0';
out = reshape(mat2cell(bi,ones(size(bi,1),1),2*ones(size(bi,2)/2,1))',1,[]);
[r,c]=size(out);
for a = 1:c
if( out{a} == [0 0])
out{a} = 'C';
else
if( out{a} == [0 1])
out{a} = 'T';
else
if( out{a} == [1 0])
out{a} = 'A';
else
if( out{a} == [1 1])
out{a} = 'G';
end
end
end
end
end
댓글 수: 1
채택된 답변
추가 답변 (1개)
Honglei Chen
2013년 2월 27일
편집: Honglei Chen
2013년 2월 27일
Sounds like a sequencing problem. You can do it like this
x = '11000100';
idx = bin2dec(reshape(x,2,[]).')+1;
matchset = 'CGTA';
matchset(idx)
댓글 수: 2
Azzi Abdelmalek
2013년 2월 27일
편집: Azzi Abdelmalek
2013년 2월 27일
Typo,
matchset(idx)
instead of
matcheset(idx)
Honglei Chen
2013년 2월 27일
corrected, thanks.
카테고리
도움말 센터 및 File Exchange에서 Library Development에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!