MATLAB: Read first column from the text file

thank you

I have a text file that contains eighty rows with six columns of data values. All I want to do is read a first column of values only. How do I read the column ?

Best Answer

fid = fopen('sample.txt')
% ^^^^^^^^^^----- your filename
formatspec=['%f',repmat('%*f',1,5)]; % 5 represents total columns - the first column
data = textscan(fid,formatspec);
fid = fclose(fid);
data{:} % first column