Encoding Binary to DNA sequencing

6 views (last 30 days)
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:
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);
% Display in command window:
Thank you
Walter Roberson
Walter Roberson on 7 Feb 2021
Yes, that is exactly the problem that was discussed in the Answer.

Sign in to comment.

Accepted Answer

Image Analyst
Image Analyst on 25 Sep 2015
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.
Walter Roberson
Walter Roberson on 26 Sep 2015
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)

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!