フィルターのクリア

split string into 3 letter each

45 ビュー (過去 30 日間)
Elysi Cochin
Elysi Cochin 2013 年 12 月 11 日
コメント済み: Mohammed Alrajeb 2019 年 8 月 19 日
if have a
str = 'AGTCTGTCTTTG';
i wanted to split it into 3 letters each
AGT CTG TCT TTG
and replace
AGT with J
CTG with U
TCT with N
TTG with D
how to do it... please do reply....
i did as below
str = 'AGTCTGTCTTTG';
j = 1;
for k = 1: 3: length(str)
word(j) = str(k : k +3)
j = j+1;
end
but i get error as
??? Subscripted assignment dimension mismatch.
Error in ==> Untitled2 at 4
word(j) = str(k : k +3)
please do reply....

採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2013 年 12 月 11 日
編集済み: Azzi Abdelmalek 2013 年 12 月 11 日
str ='AGTCTGTCTTTG';
a=cellstr(reshape(str,3,[])')
What is the aim of the replacement ? you can create
v={'J','U','N','D'}
  2 件のコメント
Azzi Abdelmalek
Azzi Abdelmalek 2013 年 12 月 11 日
If you have another string
s='AGT kdjd CTGer TCTTTG1'
str ='AGTCTGTCTTTG';
a=cellstr(reshape(str,3,[])')
v={'J','U','N','D'}
for k=1:numel(v)
s=strrep(s,a{k},v{k})
end
Mohammed Alrajeb
Mohammed Alrajeb 2019 年 8 月 19 日
hi every one.
my question is I have string of binary (00000100) 64 bits I want to take them over the number of each number is 8 bits and convert it to int8 amd use this number as input to my equation . how can i do that by function.
thanks

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

その他の回答 (2 件)

Jos (10584)
Jos (10584) 2013 年 12 月 11 日
編集済み: Jos (10584) 2013 年 12 月 11 日
In your loop code, you want to store store a string of three elements into a spot with only 1 element "word(j)". This will not fit. A solution is to use a cell array of strings, using curly brackets:
str = 'AGTCTGTCTTTG';
j = 1;
for k = 1: 3: length(str)
word{j} = str(k : k +3)
j = j+1;
end
which can be replaced by:
word = strread(str,'%3s')
or
word = mat2cell(str,1,repmat(3,1,numel(str)/3))
To replace multiple values at once you could take a look at REPLACE function, which I made available through the File Exchange:
result = replace(word,{'AGT','CTG','TCT','TTG'},{'J','U','N','D'})
REPLACE is a user-friendly wrapper function using ismember http://www.mathworks.com/matlabcentral/fileexchange/10063-replace
  1 件のコメント
Elysi Cochin
Elysi Cochin 2013 年 12 月 11 日
thank u all....

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


Mohammed Alrajeb
Mohammed Alrajeb 2019 年 8 月 19 日
hi every one.
my question is I have string of binary (00000100) 64 bits I want to take them over the number of each number is 8 bits and convert it to int8 amd use this number as input to my equation . how can i do that by function.
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