フィルターのクリア

How to import multiple .nc files of different lengths

1 回表示 (過去 30 日間)
Gemma
Gemma 2017 年 3 月 28 日
回答済み: Eeshan Mitra 2017 年 3 月 30 日
Hello,
I'm trying to import 164 3-D files of size 192x94x365(6). The files contain gridded climate data and are stored annually.
I'm struggling to import these into a single, large, 4-D file due to the extended length of the leap year files. Matlab returns a dimension mismatch.
I have this:
year=[1851:2014];
for ii=1:164
clear fnpath0 fname0 fname1;
fnpath0 = 'myfilepath';
fname0 = sprintf('uwnd.10m.%d.nc',year(ii));
fname1 = [fnpath0 fname0];
Uwndorg = ncread(fname1,'uwnd');
Uwndall(22:60,30:59,:,ii)=Uwndorg(22:60,30:59,:);
end

採用された回答

Eeshan Mitra
Eeshan Mitra 2017 年 3 月 30 日
Depending on the application, and how you want to process the data subsequently, data from matrices of unequal size may be saved using one of the two methods:
  1. Pre-process entries so as to make them all of equal size: For entries corresponding to non- 'leap years', save the 60th entry (for February 29) as NaN (not-a-number). The subsequent entries, starting from the 61st (for March 1) are therefore shifted by 1. The matlab function 'leapyear' can be used to perform checks for every instance in the loop ( https://www.mathworks.com/help/aerotbx/ug/leapyear.html ).
  2. To save data from matrices of unequal size without manipulating entries, cell arrays may be used. Find more information on indexing cell arrays and accessing data in this link: https://www.mathworks.com/help/matlab/matlab_prog/access-data-in-a-cell-array.html

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeClimate Science and Analysis についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by