"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 blank-padded to the length of the longest string.
str_ary = str2mat('name_1', 'name2'); for i = 1:2 str_len = length(str_ary(i,:)) end