I have to retrieve characters from a string array at particular index of array
Show older comments
I am creating a function to get the substrings from an array for strings but getting error Undefined function 'substring' for input arguments of type 'char'. Below is the function I wrote.Kindly, help what is wrong in that
|
function [ ] = GetSubsequence( length ,position)
seq={'ctgaataggccatctgatggaagctgaataagccatcgct','atgaataccttccatctgatggaagctgaa'};
[m ,n]=size(seq);
disp(n);
for i=1:n
sequence=seq{i};
subsequence=substring(sequence,position,length);
disp(subsequence);
end|
Accepted Answer
More Answers (2)
substring does not exist as a function in my version of Matlab (Matlab R2016b) so the error message is correct in that case.
Walter Roberson
on 24 Feb 2017
If for some reason it is mandatory to use a function named "substring" for character extraction, then you need to use the Symbolic Toolbox:
function GetSubsequence(length ,position)
seq = {'ctgaataggccatctgatggaagctgaataagccatcgct','atgaataccttccatctgatggaagctgaa'};
[m, n] = size(seq);
disp(n);
for i = 1:n
sequence = seq{i};
%strings in MuPAD must have "" around them
subsequence = feval(symengine, 'substring', ['"', sequence, '"'], position, length);
disp(subsequence);
end
I do not recommend this approach; I show it only to be pedantic about the fact that a substring function does exist.
Categories
Find more on Operations on Strings in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!