MATLAB: Does the CELLSTR function in MATLAB 7.0 (R14) and later versions not automatically deblank the input string

blankcellstrdeblankMATLABr14r14sp1strcmp

The CELLSTR function in MATLAB 7.0 (R14) and later versions does not automatically deblank a string as it did in MATLAB 6.5.1 (R13SP1).
Under MATLAB 6.5.1 (R13SP1), the STRCMPI function in the following code returns a logical 1. However, under MATLAB 7.0 (R14), STRCMPI will return a logical 0 due to this change.
w = [84, 69, 67, 72, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
x = char(w); % (1x16) char array of 'TECH'
y = cellstr(x);
z = y{1}; % (1x4) char array in MATLAB 6.5.1, (1x16) char array in MATLAB 7.0
strcmpi('TECH', z) % 1 in MATLAB 6.5.1, 0 in MATLAB 7.0

Best Answer

This bug has been fixed in Release 14 Service Pack 2 (R14SP2). For previous releases, please read below for any possible workarounds:
This is due to a change in the CELLSTR function in MATLAB 7.0 (R14) and MATLAB 7.0.1 (R14SP1). To deblank a cell array, use the DEBLANK function as follows:
w = [84, 69, 67, 72, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
x = char(w); % => (1x16) char array 'TECH'
y = cellstr(x);
z = y{1}; % => now a (1x16) char array
strcmpi('TECH', deblank(z)) % deblank the variable z and compare it to the string 'TECH'