I am trying to speed up my code. I have a 18000*36000*366 matrix. I split the matrix into 18 bands of each 1000* 36000 .bin files located in 366 folders. I plan to run the same code for 18 times. The problem is it takes 3.5hrs to process 1*36000 like I wanted. It is super slow, any help is appreciated. Below is my code,
for lat = 1:length(lat_band) % length of lat_band = 1000
for lon = 1:36000 if (mask(lat,lon)~=9) % if ocean then skip
data_1km = data; % matrix of size [366,1];
else data_1km = NaN(366,1); end tmp = 'path'; tic for day = 1:366 fwrite(fopen(sprintf('%s%d', tmp, day, '/band_1.bin'), 'a'), data_1km(day),'double'); end fclose('all'); clear data_1km day toc endend
Best Answer