Search All of the Math Forum:
Views expressed in these public forums are not endorsed by
Drexel University or The Math Forum.



Re: Length of strings?
Posted:
Nov 22, 2005 2:12 PM


"M.L." wrote: > > Hi NG, > > I have a matrix containing a number of strings: > > 'name_1' > 'name2' > 'name3' > 'name4' > > In a loop, I assign a variable (currentName) to contain string number > (i) from the array. > > How do I, in the loop, get the length of the current string contained > in "currentName"? I have tried everything, but I can only get ans = 1 > ?!
What, specifically does "everything" include? :)
However, Matlab matrices have to be conformable so that each string in the array will be blankpadded to the length of the longest string.
Something like
str_ary = str2mat('name_1', 'name2'); for i = 1:2 str_len = length(str_ary(i,:)) end
will show 6 for both strings.



