user2100039
user2100039

Reputation: 1366

Appending Matlab Data from metcdf file

I've been working on this for a while now...I have netcdf data that is in the form of 684x447x72 for each netcdf file I read using ncread(path,myvarname,[1 1 1], [684 447 72]). I need to append the data in dimension 3 for file = 2 to make the variable now 684x447x144 and so on for each new file. So, for example if I have 10 files, then the final read_in_var = 684x447x720. How do I do this within a loop reading one file at a time? Thank you!!

Upvotes: 0

Views: 55

Answers (1)

Sardar Usama
Sardar Usama

Reputation: 19689

Use matrix indexing. Considering the filenames are file1, file2, file3,... file10, the following will work:

read_in_var = zeros(684,447,720);   %Pre-allocation
for k=1:10
    read_in_var(:,:,72*(k-1)+1:72*k)) = ncread(['file',num2str(k),'.nc'], ...
        myvarname,[1 1 1], [684 447 72]);
end

Upvotes: 1

Related Questions