Hi, so here is my problem: i'd like to extract values (double) from a file where sometimes different columns are not separated by any kind of delimiter.
The text file can look like this :
if true % code
199401010312.05 54.60 38.00 0.2812.10 54.60 43.00 0.3013.10 54.60 99.00 0.3313.15 54.60100.00 0.3413.20 54.60 0.00 0.0013.25 54.60128.00 0.16end
and i'm interested in the values in the third column. The first row is a date/time and i should get rid of it.
My solution to this problem is :
if true % codefid = fopen('file');T = textscan(fid,'%s','delimiter',{'\n'});fclose(fid);ngx=39;ngy=34;n=ngx*ngy;t=5839;for i =1:t T{1}((i-1)*n+1)=[]; %get rid of the date/time which occurs every nth row
endinterest = zeros(length(T{1}),1);for i =1:length(T{1}) interest(i) = str2double(T{1}{i}(12:18)); %extract the interesting characters from every row and convert them into a double
endend
This code works, but i'm dealing with millions of rows and the loop makes the computation time really long..
If you have any idea of how to reduce the computation time, that'd be great !
Thanks
Best Answer