MATLAB: Do I receive numeric as well as string data when I use IMPORTDATA and LOAD to import a text file in MATLAB 7.2 (R2006a)

asciiloadMATLAB

I use IMPORTDATA to import a text file into MATLAB. The text file contains numbers in ASCII. Some of the numbers are enclosed by double quotes (").
In MATLAB 7.1 (R14SP3) and earlier, IMPORTDATA imports the data as a single matrix of type DOUBLE.
However, in MATLAB 7.2 (R2006a), IMPORTDATA gives me a STRUCT that contains a matrix of type DOUBLE and a cell string array, which is not what I expected.
If I directly use LOAD -ascii on the text file, I receive the following error message:
??? Error using ==> load
Unknown text on line number 1 of ASCII file \\depot02\rel\edg\cases\1-38Y2MO\sample.txt
""0"".

Best Answer

This is the intended behavior of the LOAD function. LOAD imports only numerical data and it would fail when there are double quotes mixed in the numerical data.
To import numerical text data with double quotes mixed in, use TEXTSCAN with the %q option to bring in the text file as a cell array of strings. You can then use STR2NUM and RESHAPE to convert the data into a DOUBLE matrix of the proper dimensions as shown in the example code:
fid = fopen('sample.txt'); % Open the file
data = textscan(fid,'%q'); % Read in the data
fclose(fid); % Close the file
a = cellfun(@str2num,data{1}); % Convert the string into numbers
clear data; % Data is no longer needed; remove it from memory
a = reshape(a,2,26); % Resize the matrix into the Nx26 column format