我目前正在尝试在Matlab上找到 5 个不同的 2x1 双精度数组的最小值/最大值。我在下面编写了一个有效的函数,从列出的所有 5 个数组中返回最小值和最大值。但是,它看起来又长又笨重。我想知道是否有更有效的方法来做到这一点?
我正在考虑制作一个数组数组,但我不想复制所有数据并浪费内存只是为了检查最小值和最大值。
对此有什么想法吗?谢谢!
%% Finds min/max Lat values
function results = FindRanges(hObject,handles)
% Min of Latitudes
minLat = TG_Lat;
if min(handles.AC_Lats(:)) < minLat
minLat = min(handles.AC_Lats(:));
end
if min(handles.MS_Lats(:)) < minLat
minLat = min(handles.MS_Lats(:));
end
if min(handles.DL_Lats(:)) < minLat
minLat = min(handles.DL_Lats(:));
end
if min(handles.PI_Lats(:)) < minLat
minLat = min(handles.PI_Lats(:));
end
if min(handles.EM_Lats(:)) < minLat
minLat = min(handles.EM_Lats(:));
end
% Max of Latitudes
maxLat = TG_Lat;
if max(handles.AC_Lats(:)) > maxLat
maxLat = max(handles.AC_Lats(:));
end
if max(handles.MS_Lats(:)) > maxLat
maxLat = max(handles.MS_Lats(:));
end
if max(handles.DL_Lats(:)) > maxLat
maxLat = max(handles.DL_Lats(:));
end
if max(handles.PI_Lats(:)) > maxLat
maxLat = max(handles.PI_Lats(:));
end
if max(handles.EM_Lats(:)) > maxLat
maxLat = max(handles.EM_Lats(:));
end
results = [minLat, maxLat];