I'm currently trying to find the min/max value of 5 different 2x1 arrays of doubles on Matlab. I wrote a function below that works, returning the min and max values from all 5 arrays listed. However, it looks so long and bulky. I was wondering if there was a more efficient way of doing this?
I was thinking of making an array of arrays, but I don't want to copy all that data and waste memory just to check for a min and max value.
Any ideas on this? Thanks!
%% 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];