MATLAB: A bug of build-in function Char

not a bug

Well, I have a double array readed from a binary file, such as X=[66 43 22 0 67],
When I convert the array into string, char(X), the ans is 'B+! C'
I think that the function Char() should take [0] as the ending of a string, why it treat zero also as a part of string?

Best Answer

This is where MATLAB differs from C. C will assume that 0 is the end of the string. MATLAB has explicit start and end points of the array.
If you want that functionality, you'll have to do something like:
X = [66 43 22 0 67];
char(X(1:find(X == 0,1)))