My full code is as follows. When I tried importing the 5th column (data attached as cell) directly to numbers using %f my code only gave the first line. Sorry the full file is 329MB so is too large to attach.
clear all
clc
year = '2009';
%Ensure header speck is same as file speck except replace %f with %s to
%give header text for numer varables
%The code must have %*s to miss values in the same places to give the
%correct headers
fileIDHeader = fopen('MO_Column_Headers.txt');
formatSpecHeader = '%s %s %s %s %s %*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%s';
DataHeader = textscan(fileIDHeader,formatSpecHeader, 'delimiter',',','EmptyValue',-inf);
NameOfFile = strcat('midas_marine-obs-lon-band-f_',year,'01-',year,'12.txt');
fileID = fopen(NameOfFile);
N=1000000; %Specify a block size
formatSpec = '%D %f %f %s %s %*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%f%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%s';
%In a while loop, call textscan to read each block of data. The file identifier, the format specifer, and the segment size (N), are the first three inputs to textscan. Ignore the commented lines using the CommentStyle name-value pair argument. Specify the tab delimiter using the Delimiter name-value pair argument. Then, process the data in the block. In this example, call scatter to display a scatter plot of temperature and humidity values in the block. The commands within the loop execute while the file pointer is not at the end of the file.
k=0;
Data=[]
while ~feof(fileID)
tic
k = k+1;
Data = textscan(fileID,formatSpec,N, 'delimiter',',','EmptyValue',-inf);
%Data=[Data; DataNew];
end
% selects from the MIDAS data the useful data and seperates the time stamp
% into year month day and hour.
[year,month,day] = ymd(Data{1});
[hour,minute] = hms(Data{1});
UsefulData(:,1) = year; % year
UsefulData(:,2) = month; % month
UsefulData(:,3) = day; % day
UsefulData(:,4) = hour; % hour
UsefulData(:,5) = minute; % minute
UsefulData(:,6) = Data{2}; % LATITUDE
UsefulData(:,7) = Data{3}; % LONGITUDE
UsefulData(:,8) = str2double(Data{1,4}); % stationID number
toc