Info

This question is closed. Reopen it to edit or answer.

Looping through 3d

1 view (last 30 days)
Abdinur Hussein
Abdinur Hussein on 25 May 2019
Closed: MATLAB Answer Bot on 20 Aug 2021
I have an hourly data matrix which is a 3d (41*40*744), 744 is time in hrs which is 31 days, how do I convert the 744 hrs into 744 files each with the right data?
Here is my code:
year = 2010; month = 1; rootname = '.DOMAIN1';
for ind_day = 1:31
for ind_hr = 0:23
filename = sprintf('%d%02d%02d%02d%s%',year,month,ind_day,ind_hr,rootname);
hourly_data(41,40, ?) = rate(:,:,?);
ncwrite([folder, filename], 'rate', hourly_data)
end
end
Thanks for the help

Answers (1)

Walter Roberson
Walter Roberson on 25 May 2019
dayrate = reshape(rate, [41 40 24 31]);
for ind_day = 1:31
for ind_hr = 0:23
filename = fullfile(folder, sprintf('%d%02d%02d%02d%s%',year,month,ind_day,ind_hr,rootname) );
hourly_data = rate(:,:,ind_hr, ind_day);
ncwrite(filename, 'rate', hourly_data)
end
end

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!