I am trying to convert the string into binary and sequencing with DNA,but i am getting error as follows :
Attempted to access bases(145); index out of bounds because numel(bases)=4.
Error in ==> filename at 21
result((k+1)/2) = bases(index);
What is the solution for this? Here is the code:
clc;
ui=input('enter the message:','s')
decString = unicode2native(ui,'utf-8')
hexString = dec2hex(decString)
binaryArray= dec2bin(decString,8)
bases = 'ATGC';
for k = 1 : 2 : length(binaryArray)
% Convert these two digits into a number 1 - 4.
index = 2 * binaryArray(k) + binaryArray(k+1) + 1;
% Use that index to assign a letter to our result.
result((k+1)/2) = bases(index);
end
% Display in command window:
result
Thank you

2 件のコメント

Shiva Reddy
Shiva Reddy 2021 年 2 月 7 日
It is giving error like index exceeds (4)
Walter Roberson
Walter Roberson 2021 年 2 月 7 日
Yes, that is exactly the problem that was discussed in the Answer.

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

 採用された回答

Image Analyst
Image Analyst 2015 年 9 月 25 日

0 投票

bases has only 4 elements so index must stay in the range 1,2,3,4 not 145 like you have it. Think about the logic some more.

5 件のコメント

Walter Roberson
Walter Roberson 2015 年 9 月 25 日
編集済み: Walter Roberson 2015 年 9 月 25 日
Remember your binaryArray is going to be something-by-8 but you are accessing it as if it is a vector. Also remember that the result of dec2bin() is characters not numeric so if you want numeric, subtract the character '0'
Meghashree G
Meghashree G 2015 年 9 月 25 日
編集済み: Walter Roberson 2015 年 9 月 25 日
Can u pls be more clear! i mean it would be great if u tell what code should be replaced..Thank You
Walter Roberson
Walter Roberson 2015 年 9 月 25 日
binaryArray = dec2bin(decString,8) - '0';
index = 2 * binaryArray(:,1:2:end) + binaryArray(:,2:2:end) + 1;
result = bases(index);
Meghashree G
Meghashree G 2015 年 9 月 26 日
編集済み: Walter Roberson 2015 年 9 月 26 日
The solution i got was
TGAC
TCAG
TCGT
TCAA
TCTA
TGCC
Its a vector right?
i want it to be something like this
TGAC
TCAG
TCGT
TCAA
TCTA
TGCC
i have to this sequence to other side.
Walter Roberson
Walter Roberson 2015 年 9 月 26 日
I do not see the difference between what you got and what you want.
To answer your question, though: No, it is not a vector, it is an array. Character strings in MATLAB are arrays, not individual entities. The "result" variable above is char of size 6 x 4
If you want it as a cell array of strings, then use cellstr(result)

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

その他の回答 (0 件)

カテゴリ

Community Treasure Hunt

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

Start Hunting!

Translated by