I am trying to store the longest resultant string after using the function strsplit unable to do so
eg: I have input strings such as 'R.DQDEGNFRRFPTNAVSMSADENSPFDLSNEDGAVYQRD.L'or 'L.TSNKDEEQRELLKAISNLLD'
I need store the string only between the dots (.) If there is no dot then I want the entire string. Each string may have zero, one or two dots.
part of the code which I am using:
for i=1:700
x=regexprep(txt(i,1), '\([^\(\)]*\)','');
y=(strsplit(char(x),'.'));
for j=1:3
yValues(1,j)=y{1,j};
end
end
But the string yValues is not storing the value of y, instead showing the following error:
Assignment has more non-singleton rhs dimensions than non-singleton subscripts
What am I doing wrong and are there any suggestions on how to fix it?
The issue is that
y
is a cell array and each element contains an entire string and it therefore can't be assigned to a single element in a normal arrayyvalues(1,j)
.You need
yvalues
to be a cell array and then you can assign into it just fine.Or more simply
Alternately, if you just want the longest output of
strsplit
, you can just do something like this.