MATLAB: Read colomn data from file

column dataremove headerline

Hi, I have a Unicode file as 'b.txt', contains 39 lines of header and data in other lines. I want to remove header lines and then read all data lines. I'm using this code:
FormatStr = repmat('%f ',1,12);
FileId = fopen('b.txt');
DataCell = textscan(FileId, FormatStr, 'Delimiter', ' ', 'HeaderLines', 39, 'CollectOutput', 1);
fclose(FileId);
TheData = DataCell{1};
But at final, TheData is in bad form. I want to have each column of data in a separate column in my variable TheData.
Please help me to solve it.
Thanks, Mani

Best Answer

Try
TheData = cssm();
where
function TheData = cssm()
FormatStr = repmat( '%f', 1,12 );
FileId = fopen('b.txt');
DataCell = textscan(FileId, FormatStr ...
, 'HeaderLines', 39, 'CollectOutput', true );
fclose(FileId);
TheData = DataCell{1};
end
The problem with your code has something to do with the delimiter being "one space" or "one or many spaces". And no need (/better not) to include space in the format-string. Default takes care of it. See the documentation.