Search code examples
stringmatlabcell-array

Why does MATLAB tell me the length of the string '01' is 1?


I have a cell array ab, where ab(1)='01'. MATLAB gives me that length('01')=2, but that length(ab(1))=1. Why is this? How can I make it not so?


Solution

  • the length of the first element in cell array ab is 1, because it is a single element. If you want the length of the contents of that element you need to use curly brackets, such as, length(a{1}) .