MATLAB更有效地插入数据

时间:2013-06-24 17:28:53

标签: matlab multidimensional-array concatenation interpolation

我想在循环中执行以下操作,以便更有效:

data_Clim1 = griddata(lonClim, latClim, ice_Clim(:,:,1), X, Y); 
data_Clim2 = griddata(lonClim, latClim, ice_Clim(:,:,2), X, Y); 
data_Clim3 = griddata(lonClim, latClim, ice_Clim(:,:,3), X, Y); 
data_Clim4 = griddata(lonClim, latClim, ice_Clim(:,:,4), X, Y); 
data_Clim5 = griddata(lonClim, latClim, ice_Clim(:,:,5), X, Y); 
data_Clim6 = griddata(lonClim, latClim, ice_Clim(:,:,6), X, Y); 
data_Clim7 = griddata(lonClim, latClim, ice_Clim(:,:,7), X, Y); 
data_Clim8 = griddata(lonClim, latClim, ice_Clim(:,:,8), X, Y); 
data_Clim9 = griddata(lonClim, latClim, ice_Clim(:,:,9), X, Y); 
data_Clim10 = griddata(lonClim, latClim, ice_Clim(:,:,10), X, Y); 
data_Clim11 = griddata(lonClim, latClim, ice_Clim(:,:,11), X, Y); 
data_Clim12 = griddata(lonClim, latClim, ice_Clim(:,:,12), X, Y); 

% Add together matrices
data_Clim = [data_Clim1; data_Clim2; data_Clim3; data_Clim4; ...
    data_Clim5; data_Clim6; data_Clim7; data_Clim8; data_Clim9; ...
    data_Clim10; data_Clim11; data_Clim12]; 

% Reshape to 3D matrix
data_Clim = reshape(data_Clim, 1437, 159, 12); 

基本上,我有一个360x161x12的矩阵,我需要将其内插到1437x159x12。但是,现在,使用griddata,我一次只能插入一个z维度。然后我将所有单独的矩阵组合在一起(有12个,因为它是每月一个),并将其重塑为我需要的尺寸。

我假设while循环或for循环不那么麻烦。

1 个答案:

答案 0 :(得分:1)

尝试类似:

dataClim = zeros(1437,159,12); // pre-allocation for speed
for i=1:12
  // Reshape each sub-matrix
  dataClim(:,:,i) = reshape(griddata(lonClim, latClim, ice_Clim(:,:,i), X, Y),1437,159);
end