我需要一些关于我在MATLAB中遇到的问题的建议:
我有4个变量,我不确定这样做的最佳方法是什么。我最初想过只计算从每个网格点到指定位置的GreatCircle距离,并返回具有最小距离的相应行/列索引。但是这样做,我不确定如何计算插值。
我尝试将数据重新整形为4列的矢量数据并运行meshgrid以可能使用interp2。但我最终得到了这个错误:
请求的109620x109620(44.8GB)阵列超出了最大阵列大小首选项
最有效的方法是什么?
答案 0 :(得分:0)
您正在处理大型数组。如果interp2
无法处理它,请改为使用子数组:
% Create data
format shortG
[Latitude,Longitude] = meshgrid(1:12,1:12);
Altitude = floor(1000+sortrows(rand(12,12))*1000);
Temperature = 10+20*rand(12,12);
Lat = 2.1;
Lon = 11.8;
% Find closest match point
[~,i_Lat] = min(abs(Latitude(1,:)-Lat));
[~,i_Lon] = min(abs(Longitude(:,1)-Lon));
% Select subarrays around this point.
% Minimum size of these matrices depend on the type of interpolation you perform
ia1 = max(1,i_Lat-5);
ia2 = min(size(Latitude,1),i_Lat+5);
io1 = max(1,i_Lon-5);
io2 = min(size(Latitude,2),i_Lon+5);
subLatitude = Latitude(io1:io2,ia1:ia2);
subLongitude = Longitude(io1:io2,ia1:ia2);
subAltitude = Altitude(io1:io2,ia1:ia2);
subTemperature = Temperature(io1:io2,ia1:ia2);
% Interpolate on these small arrays, and evaluate at target (Lat, Lon) point
A_out = interp2(subLatitude, subLongitude, subAltitude, Lat, Lon)
T_out = interp2(subLatitude, subLongitude, subTemperature, Lat, Lon)