Calculate daily minimum for 3D matrix data

I have a large 3D matrix of air temperatures for the entire Earth, with data formatted as lon x lat x time at hourly resolution. I want to find a reliable way to calculate the daily minimum temperature for each lat / lon location. Example:

lon = -180:10:180;
lat = -90:10:90;
time = datenum('2009-01-01 00:00','yyyy-mm-dd HH:MM'):1/24:datenum('2009-01-05 23:00','yyyy-mm-dd HH:MM');
data = randn(length(lon),length(lat),length(time));

This is my data. It includes air temperature for different places, provided with hourly resolution. The code below is my attempt to calculate the minimum value for each day.

% find number of unique days
datev = datevec(time);
[ia,ib,ic] = unique(datev(:,1:3),'rows');
uic = unique(ic);

% first re-structure data to 2d matrix
rdata = nan(length(time),length(lon)*length(lat));
for i = 1:length(ic);
    dd = data(:,:,i);
    rdata(i,:) = dd(:);        
end

% then calculate the minimum value for each day
min_data = nan(length(uic),length(lon)*length(lat));
for i = 1:length(uic);
    idx = find(ic == uic(i));    
    min_data(i,:) = min(rdata(idx,:),[],1);
end
min_data = reshape(min_data,length(lon),length(lat),length(uic));

I think this answer is correct, at least it looks like when I look at the answers.

, , (1) , (2) , , uniuque. , , 3D-.

.

+4
1

unique accumarray . 1 (numel(ic)). , ( ), , / , lat/long, min .

datev = datevec(time);
[~,~,ic] = unique(datev(:,1:3),'rows');

min_temps = accumarray(ic, (1:numel(ic))', [], @(x){min(data(:,:,x), [], 3)});
min_temps = cat(3, min_temps{:})

, 24 . 24 , , min accumarray.

reshaped = reshape(data, size(data, 1), size(data, 2), 24, []);
min_temps = squeeze(min(reshaped, [], 3));
+3
source

Source: https://habr.com/ru/post/1657405/


All Articles