how get min value of three dimensional data?

3 views (last 30 days)
Hello everyone,
I have a 3d matrix, Data = 125X135X144. here 125X135 is lat X lon and 144 is time.
I want to get the min and max matrix for every 4months. so that the output will bet, out = 125X135X36
the below code is working for nansum but not nanmin function is showing some error.
z = reshape(Data,129,135,4,[ ]);
x = nansum(z,3); % sum over every season
y = squeeze(x);
After getting the min max matrix, I need to substract the first min value of out time series from the first 4months of Data time series then second min value from the next 4month like that it will be done. so that the Final output will be 125X135X144
I hope my question is clear.
Thanks

Accepted Answer

Dinesh
Dinesh on 21 Mar 2024
Hi Vedanta,
I did not get any error while using the "nanmin" function. My code is as follows:
% Generating Sample Data
Data = rand(125, 135, 144) * 100;
DataReshaped = reshape(Data, 125, 135, 4, []);
minMatrix = zeros(size(DataReshaped, 1), size(DataReshaped, 2), size(DataReshaped, 4));
for i = 1:size(DataReshaped, 4)
minMatrix(:, :, i) = nanmin(DataReshaped(:, :, :, i), [], 3);
end
% After getting the min matrix
FinalOutput = zeros(size(Data));
for i = 1:size(DataReshaped, 4)
for j = 1:4
monthIndex = (i-1)*4 + j;
FinalOutput(:, :, monthIndex) = Data(:, :, monthIndex) - minMatrix(:, :, i);
end
end
disp(FinalOutput);
Please let me know if this is not what you are looking for and I will take a look at this again.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!