フィルターのクリア

how to have character replacement

2 ビュー (過去 30 日間)
Sharen H
Sharen H 2013 年 2 月 27 日
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 件のコメント
Jan
Jan 2013 年 2 月 27 日
編集済み: Jan 2013 年 2 月 27 日
Is A the double 11000100? If so, why do you run DEC2BIN? Or is the "A" in the text equal to "bi" in the code?

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

採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2013 年 2 月 27 日
A='11000100'
s='ACGT'
f=['11';'00';'01';'10']
b=reshape(A,2,[])'
for k=1:numel(s)
idx=find(ismember(b,f(k,:),'rows'))
c(idx)=s(k)
end
out=c(:)'
  3 件のコメント
Azzi Abdelmalek
Azzi Abdelmalek 2013 年 2 月 27 日
clear
s='GCTA'
f=['11';'00';'01';'10'];
secret=[70 77];
bi = dec2bin(secret,8);
for p=1:size(bi,1)
b=reshape(bi(p,:),2,[])';
for k=1:numel(s)
idx=find(ismember(b,f(k,:),'rows'));
c(idx)=s(k);
end
out{p}=c(:)';
end
out
Sharen H
Sharen H 2013 年 2 月 27 日
編集済み: Sharen H 2013 年 2 月 27 日
Sir if it is just reverse how should i do ie the input i have is
s=GCTA
i should replace it as
s = 11000110
Please help

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

その他の回答 (1 件)

Honglei Chen
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
Azzi Abdelmalek 2013 年 2 月 27 日
編集済み: Azzi Abdelmalek 2013 年 2 月 27 日
Typo,
matchset(idx)
instead of
matcheset(idx)
Honglei Chen
Honglei Chen 2013 年 2 月 27 日
corrected, thanks.

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

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by